Python: name changes executed (#607)

* name changes executed

* updated adr to accepted

* renamed openai base config

* renamed openai config to mixin

* added renames in user docs

* reverted mcperror

* fix tests

* remove sse from tests
This commit is contained in:
Eduard van Valkenburg
2025-09-04 17:00:38 +02:00
committed by GitHub
Unverified
parent 6310ca5be0
commit 40ab6e9d67
100 changed files with 1223 additions and 1100 deletions
@@ -14,7 +14,7 @@ Before you begin, ensure you have the following:
## Running a Basic Agent Sample
This sample demonstrates how to create and use a simple AI agent with Azure AI Foundry as the backend. It will create a basic agent using `ChatClientAgent` with `FoundryChatClient` and custom instructions.
This sample demonstrates how to create and use a simple AI agent with Azure AI Foundry as the backend. It will create a basic agent using `ChatAgent` with `FoundryChatClient` and custom instructions.
Make sure to set the following environment variables:
- `FOUNDRY_PROJECT_ENDPOINT`: Your Azure AI Foundry project endpoint
@@ -26,14 +26,14 @@ For detailed information about different ways to run examples and configure envi
```python
import asyncio
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
async def main():
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are good at telling jokes."
) as agent,
@@ -2,7 +2,7 @@
The Microsoft Agent Framework provides support for several types of agents to accommodate different use cases and requirements.
All agents implement a common protocol, `AIAgent`, which provides a consistent interface for all agent types. This allows for building common, agent agnostic, higher level functionality such as multi-agent orchestrations.
All agents implement a common protocol, `AgentProtocol`, which provides a consistent interface for all agent types. This allows for building common, agent agnostic, higher level functionality such as multi-agent orchestrations.
Let's dive into each agent type in more detail.
@@ -19,16 +19,16 @@ These agents support a wide range of functionality out of the box:
1. Structured output
1. Streaming responses
To create one of these agents, simply construct a `ChatClientAgent` using the chat client implementation of your choice.
To create one of these agents, simply construct a `ChatAgent` using the chat client implementation of your choice.
```python
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant"
) as agent
@@ -89,7 +89,7 @@ response = await agent.run("What's the weather like in Seattle?")
print(response.text)
# Streaming response (get results as they are generated)
async for chunk in agent.run_streaming("What's the weather like in Portland?"):
async for chunk in agent.run_stream("What's the weather like in Portland?"):
if chunk.text:
print(chunk.text, end="", flush=True)
```
@@ -102,13 +102,13 @@ For streaming examples, see:
Foundry agents support hosted code interpreter tools for executing Python code:
```python
from agent_framework import ChatClientAgent, HostedCodeInterpreterTool
from agent_framework import ChatAgent, HostedCodeInterpreterTool
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant that can execute Python code.",
tools=HostedCodeInterpreterTool()
@@ -123,13 +123,13 @@ For code interpreter examples, see:
## Custom agents
It is also possible to create fully custom agents that are not just wrappers around a chat client.
Agent Framework provides the `AIAgent` protocol and `AgentBase` base class, which when implemented/subclassed allows for complete control over the agent's behavior and capabilities.
Agent Framework provides the `AgentProtocol` protocol and `BaseAgent` base class, which when implemented/subclassed allows for complete control over the agent's behavior and capabilities.
```python
from agent_framework import AgentBase, AgentRunResponse, AgentRunResponseUpdate, AgentThread, ChatMessage
from agent_framework import BaseAgent, AgentRunResponse, AgentRunResponseUpdate, AgentThread, ChatMessage
from collections.abc import AsyncIterable
class CustomAgent(AgentBase):
class CustomAgent(BaseAgent):
async def run(
self,
messages: str | ChatMessage | list[str] | list[ChatMessage] | None = None,
@@ -139,8 +139,8 @@ class CustomAgent(AgentBase):
) -> AgentRunResponse:
# Custom agent implementation
pass
def run_streaming(
def run_stream(
self,
messages: str | ChatMessage | list[str] | list[ChatMessage] | None = None,
*,
@@ -2,7 +2,7 @@
The Microsoft Agent Framework provides built-in support for managing multi-turn conversations with AI agents. This includes maintaining context across multiple interactions. Different agent types and underlying services that are used to build agents may support different threading types, and the Agent Framework abstracts these differences away, providing a consistent interface for developers.
For example, when using a `ChatClientAgent` based on a Foundry agent, the conversation history is persisted in the service. While when using a `ChatClientAgent` based on chat completion with gpt-4, the conversation history is in-memory and managed by the agent.
For example, when using a `ChatAgent` based on a Foundry agent, the conversation history is persisted in the service. While when using a `ChatAgent` based on chat completion with gpt-4, the conversation history is in-memory and managed by the agent.
The differences between the underlying threading models are abstracted away via the `AgentThread` type.
@@ -56,7 +56,7 @@ response = await agent.run("Hello, how are you?", thread=resumed_thread)
For in-memory threads, you can provide a custom message store implementation to control how messages are stored and retrieved:
```python
from agent_framework import AgentThread, ChatMessageList, ChatClientAgent
from agent_framework import AgentThread, ChatMessageList, ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
@@ -71,7 +71,7 @@ def custom_message_store_factory():
return ChatMessageList() # or your custom implementation
async with AzureCliCredential() as credential:
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant",
chat_message_store_factory=custom_message_store_factory
@@ -82,7 +82,7 @@ async with AzureCliCredential() as credential:
`AIAgent` instances are stateless and the same agent instance can be used with multiple `AgentThread` instances.
Not all agents support all thread types though. For example if you are using a `ChatClientAgent` with the responses service, `AgentThread` instances created by this agent, will not work with a `ChatClientAgent` using the Foundry Agent service.
Not all agents support all thread types though. For example if you are using a `ChatAgent` with the responses service, `AgentThread` instances created by this agent, will not work with a `ChatAgent` using the Foundry Agent service.
This is because these services both support saving the conversation history in the service, and the `AgentThread`
only has a reference to this service managed thread.
@@ -93,32 +93,32 @@ It is therefore considered unsafe to use an `AgentThread` instance that was crea
Here's a complete example showing how to maintain context across multiple interactions:
```python
from agent_framework import ChatClientAgent, AgentThread
from agent_framework import ChatAgent, AgentThread
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
async def foundry_multi_turn_example():
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant"
) as agent
):
# Create a thread for persistent conversation
thread = agent.get_new_thread()
# First interaction
response1 = await agent.run("My name is Alice", thread=thread)
print(f"Agent: {response1.text}")
# Second interaction - agent remembers the name
response2 = await agent.run("What's my name?", thread=thread)
print(f"Agent: {response2.text}") # Should mention "Alice"
# Serialize thread for storage
serialized = await thread.serialize()
# Later, deserialize and continue conversation
new_thread = await agent.deserialize_thread(serialized)
response3 = await agent.run("What did we talk about?", thread=new_thread)