Files
Tao Chen 8d379168b2 Python: Improve python sample validation workflow (#7350)
* Add skill to replace hardcoded foundry project endpoint and model

* Include more samples and fix migration samples part 1

* Fix migration samples

* Replace Foundry hosted agent validation skill

* Fix hosted agent file sample

* Fix agent result format

* Reorganize jobs

* Update discovery heuristic for apps

* Split agents into even more jobs

* Add toolbox endpoint

* Add more pre configured resources

* Fix using deployed agent sample

* Add sample status

* Add playbook

* Exclude hidden folder in sample discovery

* Install autogen dependencies

* Grant azure search RBAC role

* Increase timeout for magentic

* Build search resouce id deterministically

* Remove grant in the workflow

* Move azure cli login closer to when the sample actually runs

* Refactor playbook

* Fix using deployed agent sample

* Actually save the playbooks

* Fix action syntax error

* Fix magentic sample

* Address copilot comments

* Fix link inspection

* Address comments

* Correct README

* Fix playbook path

* Remove trailing space
2026-08-03 22:28:53 +00:00

78 lines
2.2 KiB
Python

# /// script
# requires-python = ">=3.10"
# dependencies = [
# "agent-framework-openai",
# "autogen-agentchat",
# "autogen-ext[openai]",
# "python-dotenv",
# ]
# ///
# Run with any PEP 723 compatible runner, e.g.:
# uv run samples/autogen-migration/single_agent/01_basic_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())