Duibonduil commited on
Commit
a345cc8
·
verified ·
1 Parent(s): c5628a4

Upload 3 files

Browse files
examples/stream/__init__.py ADDED
File without changes
examples/stream/mcp.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "mcpServers": {
3
+ "amap-amap-sse": {
4
+ "url": "https://mcp.amap.com/sse?key=${AMAP_API_KEY}",
5
+ "timeout": 5.0,
6
+ "sse_read_timeout": 300.0
7
+ },
8
+ "playwright": {
9
+ "command": "npx",
10
+ "args": [
11
+ "@playwright/mcp@latest"
12
+ ],
13
+ "env": {
14
+ "PLAYWRIGHT_TIMEOUT": "120000",
15
+ "SESSION_REQUEST_CONNECT_TIMEOUT": "120"
16
+ }
17
+ },
18
+ "filesystem": {
19
+ "command": "npx",
20
+ "args": [
21
+ "-y",
22
+ "@modelcontextprotocol/server-filesystem",
23
+ "../examples"
24
+ ]
25
+ }
26
+ }
27
+ }
examples/stream/stream_run.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+ import asyncio
4
+ import os
5
+
6
+ from aworld.config.conf import AgentConfig, TaskConfig
7
+ from aworld.core.agent.base import Agent
8
+ from aworld.core.task import Task
9
+ from aworld.output.ui.base import AworldUI
10
+ from aworld.runner import Runners
11
+ from custom.custom_rich_aworld_ui import RichAworldUI
12
+
13
+ if __name__ == '__main__':
14
+
15
+ agent_config = AgentConfig(
16
+ llm_provider="openai",
17
+ llm_model_name=os.environ["LLM_MODEL_NAME"],
18
+ llm_api_key=os.environ["LLM_API_KEY"],
19
+ llm_base_url=os.environ["LLM_BASE_URL"]
20
+ )
21
+
22
+ amap_sys_prompt = "You are a helpful agent."
23
+ amap_agent = Agent(
24
+ conf=agent_config,
25
+ name="amap_agent",
26
+ system_prompt=amap_sys_prompt,
27
+ mcp_servers=["filesystem", "amap-amap-sse"], # MCP server name for agent to use
28
+ history_messages=100
29
+ )
30
+
31
+ user_input = ("How long does it take to drive from Hangzhou of Zhejiang to Weihai of Shandong (generate a table with columns for starting point, destination, duration, distance), "
32
+ "which cities are passed along the way, what interesting places are there along the route, "
33
+ "and finally generate the content as markdown and save it")
34
+
35
+ async def _run(agent, input):
36
+ task = Task(
37
+ input=input,
38
+ agent=agent,
39
+ conf=TaskConfig()
40
+ )
41
+
42
+ openwebui_ui = OpenAworldUI(
43
+ chat_id=chat_id,
44
+ workspace=WorkSpace.from_local_storages(
45
+ workspace_id=chat_id,
46
+ storage_path=os.path.join(os.curdir, "workspaces", chat_id),
47
+ ),
48
+ )
49
+
50
+ async for output in Runners.streamed_run_task(task).stream_events():
51
+ await AworldUI.parse_output(output, rich_ui)
52
+
53
+ asyncio.run(_run(amap_agent, user_input))