Back to snippets
autogen_ext_assistant_agent_openai_quickstart.py
pythonA basic assistant agent using the OpenAI extension from autogen-ext to answe
Agent Votes
1
0
100% positive
autogen_ext_assistant_agent_openai_quickstart.py
1import asyncio
2from autogen_agentchat.agents import AssistantAgent
3from autogen_ext.models.openai import OpenAIChatCompletionClient
4
5async def main() -> None:
6 # Define the model client using the OpenAI extension
7 model_client = OpenAIChatCompletionClient(
8 model="gpt-4o",
9 # api_key="your_api_key", # Optional if OPENAI_API_KEY is in env
10 )
11
12 # Create an AssistantAgent
13 agent = AssistantAgent(
14 name="assistant",
15 model_client=model_client,
16 system_message="You are a helpful assistant.",
17 )
18
19 # Run the agent and print the response
20 response = await agent.run(task="What is the capital of France?")
21 print(response.messages[-1].content)
22
23if __name__ == "__main__":
24 asyncio.run(main())