Quickstart

This guide will help you get started with AgentOperaโ€™s basic functionality.

๐Ÿ“‹ Prerequisites

Before starting, make sure you have:

  1. Installed AgentOpera (see installation guide)

  2. Set up your environment variables for LLM API access

๐Ÿ”‘ Setting Up Environment Variables

AgentOpera uses environment variables for API keys and model configurations.

Configure them as follows:

# OpenAI API Configuration
export MODEL_BASE_URL=https://api.openai.com/v1
export MODEL_API_KEY=your_openai_api_key
export MODEL_ID=gpt-4o  # or any other model ID you prefer

๐Ÿ‘‹ Hello World Example

Start with a simple โ€œHello Worldโ€ example:

import asyncio
import os
from agentopera.chatflow.agents import AssistantAgent
from agentopera.models.openai import OpenAIChatCompletionClient

# Create a model client using the OpenAI API key and model ID
model_client = OpenAIChatCompletionClient(
    base_url=os.getenv("MODEL_BASE_URL"),
    api_key=os.getenv("MODEL_API_KEY"),
    model=os.getenv("MODEL_ID")
)

async def main() -> None:
    # Create an assistant agent using the model client
    agent = AssistantAgent("assistant", model_client=model_client)
    # Run the agent with the task "Say 'Hello World!'"
    print(await agent.run(task="Say 'Hello World!'"))

asyncio.run(main())

Save this code to a file (e.g., hello_world.py) and run it:

python hello_world.py

๐Ÿš€ Next Steps

For more advanced usage, including:

  • Creating complex agent networks

  • Implementing custom agents

  • Deploying agents as services

Refer to our complete documentation.

๐Ÿ‘ Acknowledgements

We thank AutoGen by Microsoft for their excellent work, which inspired our Python API implementation. ๐Ÿ”— Original Project: AutoGen

Last updated