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.

agent_utils.py 1.5 kB

123456789101112131415161718192021222324252627282930313233343536
  1. from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
  2. async def solve_task(task):
  3. config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST")
  4. assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})
  5. user_proxy = UserProxyAgent(
  6. "user_proxy",
  7. code_execution_config={"work_dir": "coding", "use_docker": False},
  8. human_input_mode="NEVER",
  9. is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", ""),
  10. )
  11. await user_proxy.a_initiate_chat(assistant, message=task)
  12. await user_proxy.a_send(
  13. f"""Based on the results in above conversation, create a response for the user.
  14. While computing the response, remember that this conversation was your inner mono-logue.
  15. The user does not need to know every detail of the conversation.
  16. All they want to see is the appropriate result for their task (repeated below) in
  17. a manner that would be most useful. Response should be less than 1500 characters.
  18. The task was: {task}
  19. There is no need to use the word TERMINATE in this response.
  20. """,
  21. assistant,
  22. request_reply=False,
  23. silent=True,
  24. )
  25. response = await assistant.a_generate_reply(assistant.chat_messages[user_proxy], user_proxy)
  26. await assistant.a_send(response, user_proxy, request_reply=False, silent=True)
  27. last_message = assistant.chat_messages[user_proxy][-1]["content"]
  28. return last_message[:2000]