Agent Class
Base abstraction for all Semantic Kernel agents. An agent instance may participate in one or more conversations. A conversation may include one or more agents. In addition to identity and descriptive meta-data, an Agent must define its communication protocol, or AgentChannel. Create a new model by parsing and validating input data from keyword arguments. Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model. self is explicitly positional-only to allow self as a field name.
Constructor
Agent(
  *,
  arguments: KernelArguments | None = None,
  description: str | None = None,
  id: str | None = None,
  instructions: str | None = None,
  kernel: Kernel | None = None,
  name: Annotated[str, _PydanticGeneralMetadata(pattern='^[0-9A-Za-z_-]+$')] | None = None,
  prompt_template: PromptTemplateBase | None = None
)
Keyword-Only Parameters
| Name | Description | 
|---|---|
| arguments |  | 
| description |  | 
| id |  | 
| instructions |  | 
| kernel |  | 
| name |  | 
| prompt_template |  | 
Methods
| create_channel | Create a channel. | 
| format_instructions | Format the instructions. | 
| get_channel_keys | Get the channel keys. | 
| get_response | Get a response from the agent. This method returns the final result of the agent's execution as an AgentResponseItem containing a single ChatMessageContent object. The caller is blocked until the final result is available. Note: For streaming responses, use the invoke_stream method, which returns intermediate steps and the final result as a stream of AgentResponseItem[ StreamingChatMessageContent]. Streaming only the final result is not feasible because the timing of the final result’s availability is unknown, and blocking the caller until then is undesirable in streaming scenarios. | 
| invoke | Invoke the agent. This invocation method will return the intermediate steps and the final results of the agent's execution as an asynchronous stream of AgentResponseItem[ChatMessageContent] objects to the caller. Note: A ChatMessageContent object contains an entire message. | 
| invoke_stream | Invoke the agent as a stream. This invocation method will return the intermediate steps and final results of the agent's execution as an asynchronous stream of AgentResponseItem[StreamingChatMessageContent] objects to the caller. Note: A StreamingChatMessageContent object contains a chunk of a message. | 
create_channel
Create a channel.
async create_channel() -> AgentChannelReturns
| Type | Description | 
|---|---|
| An instance of AgentChannel. | 
format_instructions
Format the instructions.
async format_instructions(
  kernel: Kernel,
  arguments: KernelArguments | None = None
) -> str | NoneParameters
| Name | Description | 
|---|---|
| kernel 
				Required
			 | The kernel instance. | 
| arguments | The kernel arguments. Default value: None | 
Returns
| Type | Description | 
|---|---|
| The formatted instructions. | 
get_channel_keys
Get the channel keys.
get_channel_keys() -> Iterable[str]Returns
| Type | Description | 
|---|---|
| A list of channel keys. | 
get_response
Get a response from the agent. This method returns the final result of the agent's execution as an AgentResponseItem containing a single ChatMessageContent object. The caller is blocked until the final result is available. Note: For streaming responses, use the invoke_stream method, which returns intermediate steps and the final result as a stream of AgentResponseItem[ StreamingChatMessageContent]. Streaming only the final result is not feasible because the timing of the final result’s availability is unknown, and blocking the caller until then is undesirable in streaming scenarios.
abstract get_response(
  messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,
  thread: AgentThread | None = None,
  **kwargs
) -> Awaitable[AgentResponseItem[ChatMessageContent]]Parameters
| Name | Description | 
|---|---|
| messages | The message(s) to send to the agent. Default value: None | 
| thread | The conversation thread associated with the message(s). Default value: None | 
Returns
| Type | Description | 
|---|---|
| An AgentResponseItem containing the final ChatMessageContent. | 
invoke
Invoke the agent. This invocation method will return the intermediate steps and the final results of the agent's execution as an asynchronous stream of AgentResponseItem[ChatMessageContent] objects to the caller. Note: A ChatMessageContent object contains an entire message.
abstract invoke(
  messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,
  thread: AgentThread | None = None,
  **kwargs
) -> AsyncIterable[AgentResponseItem[ChatMessageContent]]Parameters
| Name | Description | 
|---|---|
| messages | The message(s) to send to the agent. Default value: None | 
| thread | The conversation thread associated with the message(s). Default value: None | 
Returns
| Type | Description | 
|---|---|
| An asynchronous stream of AgentResponseItem containing ChatMessageContent. | 
invoke_stream
Invoke the agent as a stream. This invocation method will return the intermediate steps and final results of the agent's execution as an asynchronous stream of AgentResponseItem[StreamingChatMessageContent] objects to the caller. Note: A StreamingChatMessageContent object contains a chunk of a message.
abstract invoke_stream(
  messages: str | ChatMessageContent | list[str | ChatMessageContent] | None = None,
  thread: AgentThread | None = None,
  **kwargs
) -> AsyncIterable[AgentResponseItem[StreamingChatMessageContent]]Parameters
| Name | Description | 
|---|---|
| messages | The message(s) to send to the agent. Default value: None | 
| thread | The conversation thread associated with the message(s). Default value: None | 
Returns
| Type | Description | 
|---|---|
| An asynchronous stream of AgentResponseItem containing StreamingChatMessageContent. | 
Attributes
arguments
The arguments for the agent
arguments: KernelArguments | Nonechannel_type
The type of the agent channel
channel_type: ClassVar[type[AgentChannel] | None] = Nonedescription
The description of the agent
description: str | Noneid
The unique identifier of the agent. If no id is provided, a new UUID will be generated.
id: strinstructions
The instructions for the agent (optional)
instructions: str | Nonekernel
The kernel instance for the agent
kernel: Kernelname
The name of the agent
name: strprompt_template
The prompt template for the agent
prompt_template: PromptTemplateBase | None