Coverage for docs/docs_src/user_guide/runtimes/ag2/websurfer_tool.py: 100%
13 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-19 12:16 +0000
1import os 1bacde
2from typing import Any 1bacde
4from autogen import UserProxyAgent, ConversableAgent, LLMConfig 1bacde
6from fastagency import UI, FastAgency 1bacde
7from fastagency.runtimes.ag2 import Workflow 1bacde
8from fastagency.runtimes.ag2.tools import WebSurferTool 1bacde
9from fastagency.ui.console import ConsoleUI 1bacde
11llm_config = LLMConfig( 1bacde
12 model="gpt-4o-mini",
13 api_key=os.getenv("OPENAI_API_KEY"),
14 temperature=0.8,
15)
17wf = Workflow() 1bacde
20@wf.register(name="simple_websurfer", description="WebSurfer chat") # type: ignore[type-var] 1bacde
21def websurfer_workflow( 1bacde
22 ui: UI, params: dict[str, Any]
23) -> str:
24 initial_message = ui.text_input( 1a
25 sender="Workflow",
26 recipient="User",
27 prompt="I can help you with your web search. What would you like to know?",
28 )
30 with llm_config: 1a
31 user_agent = UserProxyAgent( 1a
32 name="User_Agent",
33 system_message="You are a user agent",
34 human_input_mode="NEVER",
35 )
36 assistant_agent = ConversableAgent( 1a
37 name="Assistant_Agent",
38 system_message="You are a useful assistant",
39 human_input_mode="NEVER",
40 )
42 web_surfer = WebSurferTool( 1a
43 name_prefix="Web_Surfer",
44 llm_config=llm_config,
45 summarizer_llm_config=llm_config,
46 bing_api_key=os.getenv("BING_API_KEY"),
47 )
49 web_surfer.register( 1a
50 caller=assistant_agent,
51 executor=user_agent,
52 )
54 response = user_agent.run( 1a
55 assistant_agent,
56 message=initial_message,
57 summary_method="reflection_with_llm",
58 max_turns=3,
59 )
61 return ui.process(response) # type: ignore[no-any-return] 1a
64app = FastAgency(provider=wf, ui=ConsoleUI()) 1bacde