Python: [BREAKING] Renamed create_agent to as_agent (#3249)

* Renamed create_agent to as_agent

* Override for as_agent

* Added override
This commit is contained in:
Dmytro Struk
2026-01-16 11:21:52 -08:00
committed by GitHub
Unverified
parent a151f10cc2
commit 5687e13221
163 changed files with 498 additions and 358 deletions
@@ -377,7 +377,7 @@ class BaseChatClient(SerializationMixin, ABC, Generic[TOptions_co]):
"""
return "Unknown"
def create_agent(
def as_agent(
self,
*,
id: str | None = None,
@@ -428,7 +428,7 @@ class BaseChatClient(SerializationMixin, ABC, Generic[TOptions_co]):
client = OpenAIChatClient(model_id="gpt-4")
# Create an agent using the convenience method
agent = client.create_agent(
agent = client.as_agent(
name="assistant",
instructions="You are a helpful assistant.",
default_options={"temperature": 0.7, "max_tokens": 500},
@@ -710,9 +710,9 @@ class HandoffBuilder:
from agent_framework.openai import OpenAIChatClient
client = OpenAIChatClient()
triage = client.create_agent(instructions="...", name="triage_agent")
refund = client.create_agent(instructions="...", name="refund_agent")
billing = client.create_agent(instructions="...", name="billing_agent")
triage = client.as_agent(instructions="...", name="triage_agent")
refund = client.as_agent(instructions="...", name="refund_agent")
billing = client.as_agent(instructions="...", name="billing_agent")
builder = HandoffBuilder().participants([triage, refund, billing])
builder.with_start_agent(triage)
@@ -9,8 +9,12 @@ from collections.abc import (
Mapping,
MutableMapping,
MutableSequence,
Sequence,
)
from typing import Any, Generic, Literal, TypedDict, cast
from typing import TYPE_CHECKING, Any, Generic, Literal, TypedDict, cast
if TYPE_CHECKING:
from .._agents import ChatAgent
from openai import AsyncOpenAI
from openai.types.beta.threads import (
@@ -28,11 +32,14 @@ from openai.types.beta.threads.runs import RunStep
from pydantic import ValidationError
from .._clients import BaseChatClient
from .._middleware import use_chat_middleware
from .._memory import ContextProvider
from .._middleware import Middleware, use_chat_middleware
from .._threads import ChatMessageStoreProtocol
from .._tools import (
AIFunction,
HostedCodeInterpreterTool,
HostedFileSearchTool,
ToolProtocol,
use_function_invocation,
)
from .._types import (
@@ -761,3 +768,59 @@ class OpenAIAssistantsClient(
self.assistant_name = agent_name
if description and not self.assistant_description:
self.assistant_description = description
@override
def as_agent(
self,
*,
id: str | None = None,
name: str | None = None,
description: str | None = None,
instructions: str | None = None,
tools: ToolProtocol
| Callable[..., Any]
| MutableMapping[str, Any]
| Sequence[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]]
| None = None,
default_options: TOpenAIAssistantsOptions | None = None,
chat_message_store_factory: Callable[[], ChatMessageStoreProtocol] | None = None,
context_provider: ContextProvider | None = None,
middleware: Sequence[Middleware] | None = None,
**kwargs: Any,
) -> "ChatAgent[TOpenAIAssistantsOptions]":
"""Convert this chat client to a ChatAgent.
This method creates a ChatAgent instance with this client pre-configured.
It does NOT create an assistant on the OpenAI service - the actual assistant
will be created on the server during the first invocation (run).
For creating and managing persistent assistants on the server, use
:class:`~agent_framework.openai.OpenAIAssistantProvider` instead.
Keyword Args:
id: The unique identifier for the agent. Will be created automatically if not provided.
name: The name of the agent.
description: A brief description of the agent's purpose.
instructions: Optional instructions for the agent.
tools: The tools to use for the request.
default_options: A TypedDict containing chat options.
chat_message_store_factory: Factory function to create an instance of ChatMessageStoreProtocol.
context_provider: Context providers to include during agent invocation.
middleware: List of middleware to intercept agent and function invocations.
kwargs: Any additional keyword arguments.
Returns:
A ChatAgent instance configured with this chat client.
"""
return super().as_agent(
id=id,
name=name,
description=description,
instructions=instructions,
tools=tools,
default_options=default_options,
chat_message_store_factory=chat_message_store_factory,
context_provider=context_provider,
middleware=middleware,
**kwargs,
)