Agent API Reference
Core agent classes for building AI agents with the Microsoft Agent Framework.SupportsAgentRun
Protocol defining the interface that all agents must implement.Protocol Methods
str
required
Unique identifier for the agent
str | None
Human-readable name of the agent
str | None
Description of the agent’s purpose and capabilities
run()
Get a response from the agent.AgentRunInputs | None
The message(s) to send to the agent. Can be a string, Message, list of Messages, or None.
bool
default:"False"
Whether to stream the response. When True, returns a ResponseStream.
AgentSession | None
The conversation session associated with the message(s).
Any
Additional keyword arguments passed to the agent.
Awaitable[AgentResponse] | ResponseStream[AgentResponseUpdate, AgentResponse]
When stream=False: An AgentResponse with the final result.When stream=True: A ResponseStream of AgentResponseUpdate items with
get_final_response() for the final AgentResponse.create_session()
Create a new conversation session.Any
Additional keyword arguments for session creation.
AgentSession
A new AgentSession instance.
get_session()
Get or create a session for a service-managed session ID.str
required
The service-managed session ID.
Any
Additional keyword arguments.
AgentSession
An AgentSession instance with service_session_id set.
Example: Custom Agent Implementation
BaseAgent
Base class for all Agent Framework agents without middleware or telemetry layers.Constructor
str | None
The unique identifier of the agent. If None, a UUID will be generated.
str | None
The name of the agent.
str | None
The description of the agent.
Sequence[BaseContextProvider] | None
Context providers to include during agent invocation.
Sequence[MiddlewareTypes] | None
List of middleware to intercept agent operations.
MutableMapping[str, Any] | None
Additional properties set on the agent.
Any
Additional keyword arguments merged into additional_properties.
Methods
as_tool()
Convert the agent to a FunctionTool that can be used by other agents.str | None
The name for the tool. If None, uses the agent’s name.
str | None
The description for the tool. If None, uses the agent’s description.
str
default:"task"
The name of the function argument.
str | None
The description for the function argument.
Callable[[AgentResponseUpdate], None | Awaitable[None]] | None
Optional callback for streaming responses.
bool
default:"False"
If True, forwards parent agent’s session to sub-agent’s run() call.
FunctionTool
A FunctionTool that wraps this agent.
Agent
The main agent class for building AI agents with chat clients, tools, and instructions.Constructor
SupportsChatGetResponse
required
The chat client to use for the agent.
str | None
Instructions for the agent. These are sent to the chat client as a system message.
str | None
The unique identifier for the agent. Will be created automatically if not provided.
str | None
The name of the agent.
str | None
A brief description of the agent’s purpose.
ToolTypes | Callable | Sequence[ToolTypes | Callable] | None
The tools available to the agent. Can be FunctionTool, callable functions, or tool definitions.
ChatOptions | None
Default chat options including temperature, max_tokens, model_id, etc. Can be overridden at runtime.
Sequence[BaseContextProvider] | None
Context providers to include during agent invocation.
Sequence[MiddlewareTypes] | None
List of middleware to intercept agent and function invocations.
Any
Additional keyword arguments stored as additional_properties.
run()
Run the agent with given messages and options.AgentRunInputs | None
The messages to process. Can be string, Message, or list of Messages.
bool
default:"False"
Whether to stream the response.
AgentSession | None
The session to use for the agent. If None, the run will be stateless.
ToolTypes | Callable | Sequence[ToolTypes | Callable] | None
Tools for this specific run (merged with default tools).
ChatOptions | None
Runtime chat options including temperature, max_tokens, response_format, etc.
Any
Additional keyword arguments passed to functions that are called.
Awaitable[AgentResponse] | ResponseStream[AgentResponseUpdate, AgentResponse]
When stream=False: An Awaitable[AgentResponse] containing the agent’s response.When stream=True: A ResponseStream of AgentResponseUpdate items with
get_final_response() for the final AgentResponse.