For normal provider-backed chat agents, use agent_framework.Agent. It wraps a chat client, durable instructions, optional tools, middleware, context providers, and run/session state. The inspected signature for agent-framework==1.9.0 is:
Agent(
client: SupportsChatGetResponse[OptionsCoT],
instructions: str | None = None,
*,
id: str | None = None,
name: str | None = None,
description: str | None = None,
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
default_options: OptionsCoT | None = None,
context_providers: Sequence[ContextProvider] | None = None,
middleware: Sequence[MiddlewareTypes] | None = None,
require_per_service_call_history_persistence: bool = False,
compaction_strategy: CompactionStrategy | None = None,
tokenizer: TokenizerProtocol | None = None,
additional_properties: MutableMapping[str, Any] | None = None,
) -> None
The OpenAI provider client used in the worked example is agent_framework.openai.OpenAIChatClient. Its inspected constructor is:
OpenAIChatClient(
model: str | None = None,
*,
api_key: str | Callable[[], str | Awaitable[str]] | None = None,
credential: AzureCredentialTypes | AzureTokenProvider | None = None,
org_id: str | None = None,
base_url: str | None = None,
azure_endpoint: str | None = None,
api_version: str | None = None,
default_headers: Mapping[str, str] | None = None,
async_client: AsyncOpenAI | None = None,
instruction_role: str | None = None,
compaction_strategy: CompactionStrategy | None = None,
tokenizer: TokenizerProtocol | None = None,
middleware: Sequence[ChatAndFunctionMiddlewareTypes] | None = None,
function_invocation_configuration: FunctionInvocationConfiguration | None = None,
additional_properties: dict[str, Any] | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
) -> None
| Parameter | Use it for |
client | The provider chat client that performs model inference. Any compatible chat client can sit behind the agent boundary. |
instructions | Durable role and behavior guidance: tone, constraints, and what the agent should optimize for. |
name | A readable identity for logs, traces, multi-agent displays, and debugging. |
tools | Optional callable capabilities the agent may request when instructions alone are not enough. |
model / api_key | OpenAI client configuration. Live calls require credentials such as OPENAI_API_KEY. |
Invoke the agent with await agent.run(messages). In 1.9.0, there is no public run_stream method; streaming is selected with agent.run(..., stream=True), which returns a response stream. If you construct message objects directly, use agent_framework.Message and text content created with Content.from_text(...).
Agent.run(
self,
messages: AgentRunInputs | None = None,
*,
stream: bool = False,
session: AgentSession | None = None,
middleware: Sequence[MiddlewareTypes] | None = None,
tools: ToolTypes | Callable[..., Any] | Sequence[ToolTypes | Callable[..., Any]] | None = None,
options: OptionsCoT | ChatOptions[Any] | None = None,
compaction_strategy: CompactionStrategy | None = None,
tokenizer: TokenizerProtocol | None = None,
function_invocation_kwargs: Mapping[str, Any] | None = None,
client_kwargs: Mapping[str, Any] | None = None,
) -> Awaitable[AgentResponse[Any]] | ResponseStream[AgentResponseUpdate, AgentResponse[Any]]