The basic chat

Before we talk about multi-agent systems, you need a working single agent. In AutoGen, that means an AssistantAgent wired to a model client. Nothing fancy yet, just a clean foundation we can grow.

service.py
python
from autogen_ext.models.openai import OpenAIChatCompletionClient

def create_model_client():
    config = get_provider_config()
    model_name = config["model"]

    client_config = {
        "api_key": config["api_key"],
        "model": model_name,
    }
    if config["base_url"]:
        client_config["base_url"] = config["base_url"]
        client_config["model_info"] = {
            "function_calling": True,
            "json_output": False,
            "vision": False,
            "family": "gpt-4o",
        }
    return OpenAIChatCompletionClient(**client_config)

The model client is the bridge between AutoGen and your LLM provider. Setting function_calling=True is what makes tools possible later.

service.py
python
from autogen_agentchat.agents import AssistantAgent

def create_agent() -> AssistantAgent:
    model_client = create_model_client()
    return AssistantAgent(
        name="travel_support_assistant",
        model_client=model_client,
        system_message="You are a professional travel support assistant. Write in natural prose.",
        model_client_stream=True,
    )

An AssistantAgent wraps a model client and a system message. model_client_stream=True is the switch that makes tokens stream chunk by chunk instead of arriving as one blob.

For a single agent you do not need AutoGen. You need it the moment you want two agents to take turns, a supervisor to route messages, or a tool-execution loop that does not make you write ten state machines by hand. AutoGen gives you that loop and the agent abstractions. Today you are laying the foundation on purpose.

Quiz: Quiz

Loading practice…