# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "autogen-agentchat",
#     "autogen-ext[openai]",
# ]
# ///
# Run with any PEP 723 compatible runner, e.g.:
#   uv run samples/autogen-migration/single_agent/01_basic_assistant_agent.py

# Copyright (c) Microsoft. All rights reserved.

import asyncio

from agent_framework import Agent
from dotenv import load_dotenv

"""Basic AutoGen AssistantAgent vs Agent Framework Agent.

Both samples expect OpenAI-compatible environment variables (OPENAI_API_KEY or
Azure OpenAI configuration). Update the prompts or client wiring to match your
model of choice before running.
"""

# Load environment variables from .env file
load_dotenv()


async def run_autogen() -> None:
    """Call AutoGen's AssistantAgent for a simple question."""

    from autogen_agentchat.agents import AssistantAgent
    from autogen_ext.models.openai import OpenAIChatCompletionClient

    # AutoGen agent with OpenAI model client
    client = OpenAIChatCompletionClient(model="gpt-4.1-mini")
    agent = AssistantAgent(
        name="assistant",
        model_client=client,
        system_message="You are a helpful assistant. Answer in one sentence.",
    )

    # Run the agent (AutoGen maintains conversation state internally)
    result = await agent.run(task="What is the capital of France?")
    print("[AutoGen]", result.messages[-1].to_text())


async def run_agent_framework() -> None:
    """Call Agent Framework's Agent created from OpenAIChatClient."""
    from agent_framework.openai import OpenAIChatClient

    # AF constructs a lightweight Agent backed by OpenAIChatClient
    client = OpenAIChatClient(model="gpt-4.1-mini")
    agent = Agent(
        client=client,
        name="assistant",
        instructions="You are a helpful assistant. Answer in one sentence.",
    )

    # Run the agent (AF agents are stateless by default)
    result = await agent.run("What is the capital of France?")
    print("[Agent Framework]", result.text)


async def main() -> None:
    print("=" * 60)
    print("Basic Assistant Agent Comparison")
    print("=" * 60)
    await run_autogen()
    print()
    await run_agent_framework()


if __name__ == "__main__":
    asyncio.run(main())
