Coverage for docs/docs_src/user_guide/adapters/fastapi/security/workflows.py: 82%

11 statements  

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

1import os 1aefghibcd

2from typing import Any 1aefghibcd

3 

4from autogen import ConversableAgent, LLMConfig 1aefghibcd

5 

6from fastagency import UI 1aefghibcd

7from fastagency.runtimes.ag2 import Workflow 1aefghibcd

8 

9__init__ = ["wf"] 1aefghibcd

10 

11llm_config = LLMConfig( 1aefghibcd

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

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

14 temperature=0.8, 

15) 

16 

17wf = Workflow() 1aefghibcd

18 

19 

20@wf.register(name="simple_learning", description="Student and teacher learning chat") 1aefghibcd

21def simple_workflow(ui: UI, params: dict[str, Any]) -> str: 1aefghibcd

22 initial_message = ui.text_input( 1abcd

23 sender="Workflow", 

24 recipient="User", 

25 prompt="I can help you learn about mathematics. What subject you would like to explore?", 

26 ) 

27 

28 with llm_config: 1abcd

29 student_agent = ConversableAgent( 1abcd

30 name="Student_Agent", 

31 system_message="You are a student willing to learn.", 

32 # human_input_mode="ALWAYS", 

33 ) 

34 teacher_agent = ConversableAgent( 1a

35 name="Teacher_Agent", 

36 system_message="You are a math teacher.", 

37 # human_input_mode="ALWAYS", 

38 ) 

39 

40 response = student_agent.run( 

41 teacher_agent, 

42 message=initial_message, 

43 summary_method="reflection_with_llm", 

44 max_turns=5, 

45 ) 

46 

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