You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # AgentChat App with FastAPI
  2. This sample demonstrates how to create a simple chat application using
  3. [AgentChat](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/index.html)
  4. and [FastAPI](https://fastapi.tiangolo.com/).
  5. You will be using the following features of AgentChat:
  6. 1. Agent:
  7. - `AssistantAgent`
  8. - `UserProxyAgent` with a custom websocket input function
  9. 2. Team: `RoundRobinGroupChat`
  10. 3. State persistence: `save_state` and `load_state` methods of both agent and team.
  11. ## Setup
  12. Install the required packages with OpenAI support:
  13. ```bash
  14. pip install -U "autogen-ext[openai]" "fastapi" "uvicorn" "PyYAML"
  15. ```
  16. To use models other than OpenAI, see the [Models](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/models.html) documentation.
  17. Create a new file named `model_config.yaml` in the same directory as this README file to configure your model settings.
  18. See `model_config_template.yaml` for an example.
  19. ## Chat with a single agent
  20. To start the FastAPI server for single-agent chat, run:
  21. ```bash
  22. python app_agent.py
  23. ```
  24. Visit http://localhost:8001 in your browser to start chatting.
  25. ## Chat with a team of agents
  26. To start the FastAPI server for team chat, run:
  27. ```bash
  28. python app_team.py
  29. ```
  30. Visit http://localhost:8002 in your browser to start chatting.
  31. The team also includes a `UserProxyAgent` agent with a custom websocket input function
  32. that allows the user to send messages to the team from the browser.
  33. The team follows a round-robin strategy so each agent will take turns to respond.
  34. When it is the user's turn, the input box will be enabled.
  35. Once the user sends a message, the input box will be disabled and the agents
  36. will take turns to respond.
  37. ## State persistence
  38. The agents and team use the `load_state` and `save_state` methods to load and save
  39. their state from and to files on each turn.
  40. For the agent, the state is saved to and loaded from `agent_state.json`.
  41. For the team, the state is saved to and loaded from `team_state.json`.
  42. You can inspect the state files to see the state of the agents and team
  43. once you have chatted with them.
  44. When the server restarts, the agents and team will load their state from the state files
  45. to maintain their state across restarts.
  46. Additionally, the apps uses separate JSON files,
  47. `agent_history.json` and `team_history.json`, to store the conversation history
  48. for display in the browser.