Проблема:
У меня есть агент автогена, который должен выполнить базовую задачу навигации по веб-сайту за несколько шагов. Агент использует MCP драматурга. Агент при запуске выполняет первый шаг, а затем переходит ко второму, но просто выходит из системы, отображая странное предупреждающее сообщение. Когда я пробую этот агент в roundrobinchat, он работает как надо. Когда я запускаю его самостоятельно, он останавливается сразу после первого шага. Я новичок в autogen, я не понимаю, почему он останавливается сразу после первого шага при запуске в качестве агента и почему он не останавливается при использовании в циклическом переборе.
Отображается предупреждающее сообщение:
---------- webassistant ----------
I see the 'Reports' menu and its submenu options on the left side of the page. Next, I will open the submenu and click on the 'World xxxx Production Reports' link.
[Prompt tokens: 7045, Completion tokens: 39]
---------- Summary ----------
Number of inner messages: 2
Total prompt tokens: 8595
Total completion tokens: 63
Duration: 4.73 seconds
:0: RuntimeWarning: Cannot safely stop actor at [McpWorkbench.__del__]: loop is closed or not running
Мой код:
import asyncio, sys
from autogen_agentchat.agents import AssistantAgent
import os
from dotenv import load_dotenv, dotenv_values
from autogen_core.models import UserMessage
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from autogen_ext.tools.mcp import StdioServerParams, McpWorkbench
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.ui import Console
import yaml
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.messages import TextMessage
from autogen_core import CancellationToken
# load credentials
load_dotenv(override=True)
azure_openai_api_key=os.getenv("AZURE_OPENAI_API_KEY")
azure_openai_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
azure_openai_api_version=os.getenv("AZURE_OPENAI_API_VERSION")
azure_deployment=os.getenv("AZURE_DEPLOYMENT")
# load yaml system prompt
with open("prompt_basic.yml", "r") as f:
yaml_data=yaml.safe_load(f)
system_prompt=yaml_data['webassistant_prompt']
webnavigation_server_params=StdioServerParams(command="npx",
args= [
"@playwright/mcp@latest"
],
read_timeout_seconds=60)
fs_workbench=McpWorkbench(webnavigation_server_params)
async def main():
az_model_client = AzureOpenAIChatCompletionClient(
azure_deployment=azure_deployment,
model=azure_deployment,
api_version=azure_openai_api_version,
azure_endpoint=azure_openai_endpoint,
)
async with fs_workbench as fs_wb:
webassistant=AssistantAgent(name="webassistant",
workbench=fs_wb,
model_client=az_model_client,
system_message=system_prompt,
reflect_on_tool_use=True
)
await Console(webassistant.on_messages_stream(
messages=[TextMessage(source="User", content="")],
cancellation_token=CancellationToken()
),
output_stats=True)
#await Console(webassistant.run_stream(task=""))
asyncio.run(main())
Моя подсказка:
webassistant_prompt: |
You are a webpage surfer. You have the following list of tasks. You need to perform ALL the tasks and only then hand over your output:
1. Navigate to the following website: https://xxxx/xxxx
2. Look for the 'Reports' menu, open it and in the submenu click on the 'World Production Reports' link
3. Look for the latest 'World Production' monthly report and click on it
4. Wait for the page to load, once loaded click on the current report
5. Wait till the pdf gets loaded.
6. Get and store the raw URL in a python dictionary. Example: 'production_data':'https://url.address.com/pdf_link'
7. Navigate to the following website: https://xxxx/xxxx
8. Look for the 'Reports' menu, open it and in the submenu click on the 'World Markets and Trade Reports' link
9. Wait for the page to load, and look particularly for latest xxxx related monthly report and click on it. It must be xxxx , all other xxxx are not in scope, so make sure it starts with "xxxx:". You have to scroll down to see the reports for all xxxx. If you cannot find xxxx report you need to navigate to previous reports using the navigation pages at the bottom of the page.
10. Once the page is loaded click on the current report
11. Get and store the raw URL in the previously createad python dictionary. Example: 'market_data':'https://url.address.com/pdf_link' You have two items in your python dictionary now.
12. Print the python dictionary and return it as your ONLY ouptut.