Coverage for docs/docs_src/user_guide/runtimes/ag2/websurfer.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-19 12:16 +0000

1import os 1bacde

2from typing import Any 1bacde

3 

4from autogen import UserProxyAgent, LLMConfig 1bacde

5 

6from fastagency import UI, FastAgency 1bacde

7from fastagency.runtimes.ag2 import Workflow 1bacde

8from fastagency.runtimes.ag2.agents.websurfer import WebSurferAgent 1bacde

9from fastagency.ui.console import ConsoleUI 1bacde

10 

11llm_config = LLMConfig( 1bacde

12 model="gpt-4o-mini", 

13 api_key=os.getenv("OPENAI_API_KEY"), 

14 temperature=0.8, 

15) 

16 

17wf = Workflow() 1bacde

18 

19@wf.register(name="simple_websurfer", description="WebSurfer chat") # type: ignore[type-var] 1bacde

20def websurfer_workflow( 1bacde

21 ui: UI, params: dict[str, Any] 

22) -> str: 

23 initial_message = ui.text_input( 1a

24 sender="Workflow", 

25 recipient="User", 

26 prompt="I can help you with your web search. What would you like to know?", 

27 ) 

28 user_agent = UserProxyAgent( 1a

29 name="User_Agent", 

30 system_message="You are a user agent", 

31 llm_config=llm_config, 

32 human_input_mode="NEVER", 

33 ) 

34 web_surfer = WebSurferAgent( 1a

35 name="Assistant_Agent", 

36 llm_config=llm_config, 

37 summarizer_llm_config=llm_config, 

38 human_input_mode="NEVER", 

39 executor=user_agent, 

40 bing_api_key=os.getenv("BING_API_KEY"), 

41 ) 

42 

43 response = user_agent.run( 1a

44 web_surfer, 

45 message=initial_message, 

46 summary_method="reflection_with_llm", 

47 max_turns=5, 

48 ) 

49 

50 return ui.process(response) # type: ignore[no-any-return] 1a

51 

52 

53app = FastAgency(provider=wf, ui=ConsoleUI()) 1bacde