-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathexample.py
More file actions
90 lines (80 loc) · 4.12 KB
/
example.py
File metadata and controls
90 lines (80 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Example usage of Minion Agent."""
import asyncio
import logging
from dotenv import load_dotenv
import os
from PIL import Image
from io import BytesIO
from time import sleep
from typing import List, Dict, Optional
from smolagents import (Tool, ChatMessage)
from smolagents.models import parse_json_if_needed
from custom_azure_model import CustomAzureOpenAIServerModel
import minion_agent
from minion_agent.config import MCPStdio, MCPSse
from minion_agent.logging import setup_logger
from minion_agent.tools.run_apple_script import run_applescript, run_applescript_capture, run_command
# Load environment variables from .env file
load_dotenv()
from minion_agent import MinionAgent, AgentConfig, AgentFramework
from minion.agents import (
CodeAgent,
ToolCallingAgent,
)
from minion_agent.frameworks.minion import SurrogateModel
# Configure the agent
agent_config = AgentConfig(
model_id=os.environ.get("AZURE_DEPLOYMENT_NAME"),
name="research_assistant",
description="A helpful research assistant",
model_args={"azure_endpoint": os.environ.get("AZURE_OPENAI_ENDPOINT"),
"api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
"api_version": os.environ.get("OPENAI_API_VERSION"),
"model": "gpt-4o", # Actual model to use in minion framework
},
tools=[
minion_agent.tools.browser_tool.browser,
MCPStdio(
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem","/Users/femtozheng/workspace","/Users/femtozheng/python-project/minion-agent"]
),
],
agent_type=CodeAgent,
)
# setup_logger(logging.DEBUG)
async def main():
try:
# Create and run the agent
agent = await MinionAgent.create_async(AgentFramework.EXTERNAL_MINION_AGENT, agent_config)
#agent = await MinionAgent.create_async(AgentFramework.TINYAGENT, agent_config)
# Run the agent with a question
#result = await agent.run_async("search sam altman and export summary as markdown")
#result = await agent.run_async("What are the latest developments in AI, find this information and export as markdown")
result = await agent.run_async("list files in current dir")
#result = await agent.run_async("打开微信公众号")
#result = await agent.run_async("搜索最新的人工智能发展趋势,并且总结为markdown")
#result = agent.run("go visit https://www.baidu.com and clone it")
#result = await agent.run_async("复刻一个电商网站,例如京东")
#result = await agent.run_async("go visit https://www.baidu.com , take a screenshot and clone it")
#result = await agent.run("实现一个贪吃蛇游戏")
#result = await agent.run_async("Let $\mathcal{B}$ be the set of rectangular boxes with surface area $54$ and volume $23$. Let $r$ be the radius of the smallest sphere that can contain each of the rectangular boxes that are elements of $\mathcal{B}$. The value of $r^2$ can be written as $\frac{p}{q}$, where $p$ and $q$ are relatively prime positive integers. Find $p+q$.")
#result = await agent.run_async("使用apple script帮我看一下微信上发给'新智元 ASI' hello")
#result = await agent.run_async("使用apple script帮我添加一个note, 明天早上8:00我要锻炼,并且添加到提醒, 并且发信给femtowin@gmail.com")
#result = await agent.run_async("提醒今晚9:15鼠标要充电")
# result = await agent.run_async("Write a 500000 characters novel named 'Reborn in Skyrim'. "
# "Fill the empty nodes with your own ideas. Be creative! Use your own words!"
# "I will tip you $100,000 if you write a good novel."
# "Since the novel is very long, you may need to divide it into subtasks.")
print("Agent's response:", result.final_output.content)
#await agent.close()
print("done")
except Exception as e:
print(f"Error: {str(e)}")
import traceback
traceback.print_exc()
# 如果需要调试
# import litellm
# litellm._turn_on_debug()
raise
if __name__ == "__main__":
asyncio.run(main())