-
Notifications
You must be signed in to change notification settings - Fork 891
Python: ADR for create/get agent API #2618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dmytrostruk
wants to merge
9
commits into
microsoft:main
Choose a base branch
from
dmytrostruk:create-agent-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−0
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
00f733c
ADR for create/get agent API
dmytrostruk cd815aa
Merge branch 'main' into create-agent-updates
dmytrostruk 9095e18
Merge branch 'main' into create-agent-updates
dmytrostruk 4a97abe
Merge branch 'main' into create-agent-updates
dmytrostruk 8212dd6
Merge branch 'main' into create-agent-updates
dmytrostruk 8dfb988
Merge branch 'main' into create-agent-updates
dmytrostruk 29faa12
Merge branch 'main' into create-agent-updates
dmytrostruk 5cada6e
Updated ADR with implementation options
dmytrostruk e8907b0
Merge branch 'main' into create-agent-updates
dmytrostruk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| status: proposed | ||
| contact: dmytrostruk | ||
| date: 2025-12-03 | ||
| deciders: dmytrostruk, markwallace-microsoft, eavanvalkenburg, giles17 | ||
| --- | ||
|
|
||
| # Create/Get Agent API | ||
|
|
||
| ## Context and Problem Statement | ||
|
|
||
| There is a misalignment between the create/get agent API in the .NET and Python implementations. | ||
|
|
||
| In .NET, the `CreateAIAgent` method can create either a local instance of an agent or a remote instance if the backend provider supports it. For remote agents, once the agent is created, you can retrieve an existing remote agent by using the `GetAIAgent` method. If a backend provider doesn't support remote agents, `CreateAIAgent` just initializes a new local agent instance and `GetAIAgent` is not available. There is also a `BuildAIAgent` method, which is an extension for the `ChatClientBuilder` class from `Microsoft.Extensions.AI`. It builds pipelines of `IChatClient` instances with an `IServiceProvider`. This functionality does not exist in Python, so `BuildAIAgent` is out of scope. | ||
|
|
||
| In Python, there is only one `create_agent` method, which always creates a local instance of the agent. If the backend provider supports remote agents, the remote agent is created only on the first `agent.run()` invocation. | ||
|
|
||
| Below is a short summary of different providers and their APIs in .NET: | ||
|
|
||
| | Package | Method | Behavior | Python support | | ||
| |---|---|---|---| | ||
| | Microsoft.Agents.AI | `CreateAIAgent` (based on `IChatClient`) | Creates a local instance of `ChatClientAgent`. | Yes (`create_agent` in `BaseChatClient`). | | ||
| | Microsoft.Agents.AI.Anthropic | `CreateAIAgent` (based on `IBetaService` and `IAnthropicClient`) | Creates a local instance of `ChatClientAgent`. | Yes (`AnthropicClient` inherits `BaseChatClient`, which exposes `create_agent`). | | ||
| | Microsoft.Agents.AI.AzureAI (V2) | `GetAIAgent` (based on `AIProjectClient` with `AgentReference`) | Creates a local instance of `ChatClientAgent`. | Partial (Python uses `create_agent` from `BaseChatClient`). | | ||
| | Microsoft.Agents.AI.AzureAI (V2) | `GetAIAgent`/`GetAIAgentAsync` (with `Name`/`ChatClientAgentOptions`) | Fetches `AgentRecord` via HTTP, then creates a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.AzureAI (V2) | `CreateAIAgent`/`CreateAIAgentAsync` (based on `AIProjectClient`) | Creates a remote agent first, then wraps it into a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.AzureAI.Persistent (V1) | `GetAIAgent` (based on `PersistentAgentsClient` with `PersistentAgent`) | Creates a local instance of `ChatClientAgent`. | Partial (Python uses `create_agent` from `BaseChatClient`). | | ||
| | Microsoft.Agents.AI.AzureAI.Persistent (V1) | `GetAIAgent`/`GetAIAgentAsync` (with `AgentId`) | Fetches `PersistentAgent` via HTTP, then creates a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.AzureAI.Persistent (V1) | `CreateAIAgent`/`CreateAIAgentAsync` | Creates a remote agent first, then wraps it into a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.OpenAI | `GetAIAgent` (based on `AssistantClient` with `Assistant`) | Creates a local instance of `ChatClientAgent`. | Partial (Python uses `create_agent` from `BaseChatClient`). | | ||
| | Microsoft.Agents.AI.OpenAI | `GetAIAgent`/`GetAIAgentAsync` (with `AgentId`) | Fetches `Assistant` via HTTP, then creates a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.OpenAI | `CreateAIAgent`/`CreateAIAgentAsync` (based on `AssistantClient`) | Creates a remote agent first, then wraps it into a local `ChatClientAgent` instance. | No | | ||
| | Microsoft.Agents.AI.OpenAI | `CreateAIAgent` (based on `ChatClient`) | Creates a local instance of `ChatClientAgent`. | Yes (`create_agent` in `BaseChatClient`). | | ||
| | Microsoft.Agents.AI.OpenAI | `CreateAIAgent` (based on `OpenAIResponseClient`) | Creates a local instance of `ChatClientAgent`. | Yes (`create_agent` in `BaseChatClient`). | | ||
|
|
||
| ## Decision Drivers | ||
|
|
||
| - API should be aligned between .NET and Python. | ||
| - API should be intuitive and consistent between backend providers in .NET and Python. | ||
|
|
||
| ## Considered Options | ||
|
|
||
| Add missing implementations on the Python side. This should include the following: | ||
|
|
||
| ### agent-framework-azure-ai (both V1 and V2) | ||
|
|
||
| - Add a `get_agent` method that accepts an underlying SDK agent instance and creates a local instance of `ChatAgent`. | ||
dmytrostruk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Add a `get_agent` method that accepts an agent identifier, performs an additional HTTP request to fetch agent data, and then creates a local instance of `ChatAgent`. | ||
| - Override the `create_agent` method from `BaseChatClient` to create a remote agent instance and wrap it into a local `ChatAgent`. | ||
|
|
||
| .NET: | ||
|
|
||
| ```csharp | ||
| var agent1 = new AIProjectClient(...).GetAIAgent(agentSdkInstance); // Creates a local ChatClientAgent instance | ||
| var agent2 = new AIProjectClient(...).GetAIAgent(agentName); // Fetches agent data, creates a local ChatClientAgent instance | ||
| var agent3 = new AIProjectClient(...).CreateAIAgent(...); // Creates a remote agent, returns a local ChatClientAgent instance | ||
| ``` | ||
|
|
||
| Python: | ||
|
|
||
| ```python | ||
| agent1 = AIProjectClient(...).get_agent(agent_sdk_instance) # Creates a local ChatAgent instance | ||
dmytrostruk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| agent2 = AIProjectClient(...).get_agent(agent_name) # Fetches agent data, creates a local ChatAgent instance | ||
| agent3 = AIProjectClient(...).create_agent(...) # Creates a remote agent, returns a local ChatAgent instance | ||
dmytrostruk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### agent-framework-core (OpenAI Assistants) | ||
|
|
||
| - Add a `get_agent` method that accepts an underlying SDK agent instance and creates a local instance of `ChatAgent`. | ||
| - Add a `get_agent` method that accepts an agent name, performs an additional HTTP request to fetch agent data, and then creates a local instance of `ChatAgent`. | ||
| - Override the `create_agent` method from `BaseChatClient` to create a remote agent instance and wrap it into a local `ChatAgent`. | ||
|
|
||
| .NET: | ||
|
|
||
| ```csharp | ||
| var agent1 = new AssistantClient(...).GetAIAgent(agentSdkInstance); // Creates a local ChatClientAgent instance | ||
| var agent2 = new AssistantClient(...).GetAIAgent(agentId); // Fetches agent data, creates a local ChatClientAgent instance | ||
| var agent3 = new AssistantClient(...).CreateAIAgent(...); // Creates a remote agent, returns a local ChatClientAgent instance | ||
| ``` | ||
|
|
||
| Python: | ||
|
|
||
| ```python | ||
| agent1 = OpenAIAssistantsClient(...).get_agent(agent_sdk_instance) # Creates a local ChatAgent instance | ||
| agent2 = OpenAIAssistantsClient(...).get_agent(agent_name) # Fetches agent data, creates a local ChatAgent instance | ||
| agent3 = OpenAIAssistantsClient(...).create_agent(...) # Creates a remote agent, returns a local ChatAgent instance | ||
| ``` | ||
|
|
||
| ## Decision Outcome | ||
|
|
||
| TBD | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.