mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Python: Provider-leading client design & OpenAI package extraction (#4818)
* Python: Provider-leading client design & OpenAI package extraction Major refactoring of the Python Agent Framework client architecture: - Extract OpenAI clients into new `agent-framework-openai` package - Core package no longer depends on openai, azure-identity, azure-ai-projects - Rename clients for discoverability: OpenAIResponsesClient → OpenAIChatClient, OpenAIChatClient → OpenAIChatCompletionClient - Unify `model_id`/`deployment_name`/`model_deployment_name` → `model` param - New FoundryChatClient for Azure AI Foundry Responses API - New FoundryAgent/FoundryAgentClient for connecting to pre-configured Foundry agents - Remove OpenAIBase/OpenAIConfigMixin from non-deprecated client MRO - Deprecate AzureOpenAI* clients, AzureAIClient, OpenAIAssistantsClient - Reorganize samples: azure_openai+azure_ai+azure_ai_agent → azure/ - ADR-0020: Provider-Leading Client Design Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: missing Agent imports in samples, .model_id → .model in foundry_local sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: CI failures — mypy errors, coverage targets, sample imports - azure-ai mypy: add type ignores for TypedDict total=, model arg, forward ref - Coverage: replace core.azure/openai targets with openai package target - project_provider: add type annotation for opts dict Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: populate openai .pyi stub, fix broken README links, coverage targets Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fixes * updated observabilitty * reset azure init.pyi * fix errors * updated adr number * fix foundry local * fixed not renamed docstrings and comments, and added deprecated markers to old classes * fix tests and pyprojects * fix test vars * updated function tests * update durable * updated test setup for functions * Fix Foundry auth in workflow samples Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Stabilize Python integration workflows Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update hosting samples for Foundry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Trigger full CI rerun Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Trigger CI rerun again Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * trigger rerun * trigger rerun * fix for litellm * undo durabletask changes * Move Foundry APIs into foundry namespace Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Foundry pyproject formatting Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Split provider samples by Foundry surface Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Restore hosting sample requirements Also fix the Foundry Local sample link after the provider sample move. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * updated tests * udpated foundry integration tests * removed dist from azurefunctions tests * Use separate Foundry clients for concurrent agents Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix client setup in azfunc and durable * disabled two tests * updated setup for some function and durable tests * improved azure openai setup with new clients * ignore deprecated * fixes * skip 11 * remove openai assistants int tests --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
4b533608b6
commit
5e056b672e
@@ -3,7 +3,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Message
|
||||
from agent_framework import Agent, Message
|
||||
from dotenv import load_dotenv
|
||||
|
||||
"""AutoGen RoundRobinGroupChat vs Agent Framework GroupChatBuilder/SequentialBuilder.
|
||||
@@ -68,17 +68,20 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.as_agent(
|
||||
researcher = Agent(
|
||||
client=client,
|
||||
name="researcher",
|
||||
instructions="You are a researcher. Provide facts and data about the topic.",
|
||||
)
|
||||
|
||||
writer = client.as_agent(
|
||||
writer = Agent(
|
||||
client=client,
|
||||
name="writer",
|
||||
instructions="You are a writer. Turn research into engaging content.",
|
||||
)
|
||||
|
||||
editor = client.as_agent(
|
||||
editor = Agent(
|
||||
client=client,
|
||||
name="editor",
|
||||
instructions="You are an editor. Review and finalize the content.",
|
||||
)
|
||||
@@ -99,6 +102,7 @@ async def run_agent_framework() -> None:
|
||||
async def run_agent_framework_with_cycle() -> None:
|
||||
"""Agent Framework's WorkflowBuilder with cyclic edges and conditional exit."""
|
||||
from agent_framework import (
|
||||
Agent,
|
||||
AgentExecutorRequest,
|
||||
AgentExecutorResponse,
|
||||
AgentResponseUpdate,
|
||||
@@ -111,17 +115,20 @@ async def run_agent_framework_with_cycle() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.as_agent(
|
||||
researcher = Agent(
|
||||
client=client,
|
||||
name="researcher",
|
||||
instructions="You are a researcher. Provide facts and data about the topic.",
|
||||
)
|
||||
|
||||
writer = client.as_agent(
|
||||
writer = Agent(
|
||||
client=client,
|
||||
name="writer",
|
||||
instructions="You are a writer. Turn research into engaging content.",
|
||||
)
|
||||
|
||||
editor = client.as_agent(
|
||||
editor = Agent(
|
||||
client=client,
|
||||
name="editor",
|
||||
instructions="You are an editor. Review and finalize the content. End with APPROVED if satisfied.",
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Message
|
||||
from agent_framework import Agent, Message
|
||||
from dotenv import load_dotenv
|
||||
|
||||
"""AutoGen SelectorGroupChat vs Agent Framework GroupChatBuilder.
|
||||
@@ -71,22 +71,22 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
from agent_framework.orchestrations import GroupChatBuilder
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
python_expert = client.as_agent(
|
||||
python_expert = Agent(client=client,
|
||||
name="python_expert",
|
||||
instructions="You are a Python programming expert. Answer Python-related questions.",
|
||||
description="Expert in Python programming",
|
||||
)
|
||||
|
||||
javascript_expert = client.as_agent(
|
||||
javascript_expert = Agent(client=client,
|
||||
name="javascript_expert",
|
||||
instructions="You are a JavaScript programming expert. Answer JavaScript-related questions.",
|
||||
description="Expert in JavaScript programming",
|
||||
)
|
||||
|
||||
database_expert = client.as_agent(
|
||||
database_expert = Agent(client=client,
|
||||
name="database_expert",
|
||||
instructions="You are a database expert. Answer SQL and database-related questions.",
|
||||
description="Expert in databases and SQL",
|
||||
@@ -95,7 +95,7 @@ async def run_agent_framework() -> None:
|
||||
workflow = GroupChatBuilder(
|
||||
participants=[python_expert, javascript_expert, database_expert],
|
||||
max_rounds=1,
|
||||
orchestrator_agent=client.as_agent(
|
||||
orchestrator_agent=Agent(client=client,
|
||||
name="selector_manager",
|
||||
instructions="Based on the conversation, select the most appropriate expert to respond next.",
|
||||
),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from agent_framework import AgentResponseUpdate, WorkflowEvent
|
||||
from agent_framework import Agent, AgentResponseUpdate, WorkflowEvent
|
||||
from dotenv import load_dotenv
|
||||
|
||||
"""AutoGen Swarm pattern vs Agent Framework HandoffBuilder.
|
||||
@@ -110,10 +110,10 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
from agent_framework.orchestrations import HandoffAgentUserRequest, HandoffBuilder
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
|
||||
# Create triage agent
|
||||
triage_agent = client.as_agent(
|
||||
triage_agent = Agent(client=client,
|
||||
name="triage",
|
||||
instructions=(
|
||||
"You are a triage agent. Analyze the user's request and route to the appropriate specialist:\n"
|
||||
@@ -124,14 +124,14 @@ async def run_agent_framework() -> None:
|
||||
)
|
||||
|
||||
# Create billing specialist
|
||||
billing_agent = client.as_agent(
|
||||
billing_agent = Agent(client=client,
|
||||
name="billing_agent",
|
||||
instructions="You are a billing specialist. Help with payment and billing questions. Provide clear assistance.",
|
||||
description="Handles billing and payment questions",
|
||||
)
|
||||
|
||||
# Create technical support specialist
|
||||
tech_support = client.as_agent(
|
||||
tech_support = Agent(client=client,
|
||||
name="technical_support",
|
||||
instructions="You are technical support. Help with technical issues. Provide clear assistance.",
|
||||
description="Handles technical support questions",
|
||||
|
||||
@@ -5,6 +5,7 @@ import json
|
||||
from typing import cast
|
||||
|
||||
from agent_framework import (
|
||||
Agent,
|
||||
AgentResponseUpdate,
|
||||
Message,
|
||||
WorkflowEvent,
|
||||
@@ -78,19 +79,22 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.as_agent(
|
||||
researcher = Agent(
|
||||
client=client,
|
||||
name="researcher",
|
||||
instructions="You are a research analyst. Gather and analyze information.",
|
||||
description="Research analyst for data gathering",
|
||||
)
|
||||
|
||||
coder = client.as_agent(
|
||||
coder = Agent(
|
||||
client=client,
|
||||
name="coder",
|
||||
instructions="You are a programmer. Write code based on requirements.",
|
||||
description="Software developer for implementation",
|
||||
)
|
||||
|
||||
reviewer = client.as_agent(
|
||||
reviewer = Agent(
|
||||
client=client,
|
||||
name="reviewer",
|
||||
instructions="You are a code reviewer. Review code for quality and correctness.",
|
||||
description="Code reviewer for quality assurance",
|
||||
@@ -99,7 +103,8 @@ async def run_agent_framework() -> None:
|
||||
# Create Magentic workflow
|
||||
workflow = MagenticBuilder(
|
||||
participants=[researcher, coder, reviewer],
|
||||
manager_agent=client.as_agent(
|
||||
manager_agent=Agent(
|
||||
client=client,
|
||||
name="magentic_manager",
|
||||
instructions="You coordinate a team to complete complex tasks efficiently.",
|
||||
description="Orchestrator for team coordination",
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
# /// 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.
|
||||
@@ -39,8 +50,9 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF constructs a lightweight Agent backed by OpenAIChatClient
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.as_agent(
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
agent = Agent(
|
||||
client=client,
|
||||
name="assistant",
|
||||
instructions="You are a helpful assistant. Answer in one sentence.",
|
||||
)
|
||||
|
||||
@@ -54,11 +54,11 @@ async def run_autogen() -> None:
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
"""Agent Framework agent with @tool decorator."""
|
||||
from agent_framework import tool
|
||||
from agent_framework import Agent, tool
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# Define tool with @tool decorator (automatic schema inference)
|
||||
# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; see samples/02-agents/tools/function_tool_with_approval.py and samples/02-agents/tools/function_tool_with_approval_and_sessions.py.
|
||||
# NOTE: approval_mode="never_require" is for sample brevity.
|
||||
@tool(approval_mode="never_require")
|
||||
def get_weather(location: str) -> str:
|
||||
"""Get the weather for a location.
|
||||
@@ -72,8 +72,8 @@ async def run_agent_framework() -> None:
|
||||
return f"The weather in {location} is sunny and 72°F."
|
||||
|
||||
# Create agent with tool
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.as_agent(
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
agent = Agent(client=client,
|
||||
name="assistant",
|
||||
instructions="You are a helpful assistant. Use available tools to answer questions.",
|
||||
tools=[get_weather],
|
||||
|
||||
+14
-2
@@ -1,7 +1,18 @@
|
||||
# /// 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/03_assistant_agent_thread_and_stream.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Agent
|
||||
from dotenv import load_dotenv
|
||||
|
||||
"""AutoGen vs Agent Framework: Thread management and streaming responses.
|
||||
@@ -46,8 +57,9 @@ async def run_agent_framework() -> None:
|
||||
"""Agent Framework agent with explicit session and streaming."""
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.as_agent(
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
agent = Agent(
|
||||
client=client,
|
||||
name="assistant",
|
||||
instructions="You are a helpful math tutor.",
|
||||
)
|
||||
|
||||
@@ -55,13 +55,13 @@ async def run_autogen() -> None:
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
"""Agent Framework's as_tool() for hierarchical agents with streaming."""
|
||||
from agent_framework import Content
|
||||
from agent_framework import Agent, Content
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
client = OpenAIChatClient(model="gpt-4.1-mini")
|
||||
|
||||
# Create specialized writer agent
|
||||
writer = client.as_agent(
|
||||
writer = Agent(client=client,
|
||||
name="writer",
|
||||
instructions="You are a creative writer. Write short, engaging content.",
|
||||
)
|
||||
@@ -75,7 +75,7 @@ async def run_agent_framework() -> None:
|
||||
)
|
||||
|
||||
# Create coordinator agent with writer tool
|
||||
coordinator = client.as_agent(
|
||||
coordinator = Agent(client=client,
|
||||
name="coordinator",
|
||||
instructions="You coordinate with specialized agents. Delegate writing tasks to the writer agent.",
|
||||
tools=[writer_tool],
|
||||
|
||||
Reference in New Issue
Block a user