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, instructions: str | None = None, kernel: Kernel = None, name: Annotated[str, _PydanticGeneralMetadata(pattern='^[0-9A-Za-z_-]+$')] = None, prompt_template: PromptTemplateBase | None = None)
Keyword-Only Parameters
Name | Description |
---|---|
arguments
Required
|
|
description
Required
|
|
id
Required
|
|
instructions
Required
|
|
kernel
Required
|
|
name
Required
|
|
prompt_template
Required
|
|
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 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 StreamingChatMessageContent objects. 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 a stream of 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 a stream of StreamingChatMessageContent objects to the caller. Note: A StreamingChatMessageContent object contains a chunk of a message. |
create_channel
Create a channel.
async create_channel() -> AgentChannel
Returns
Type | Description |
---|---|
An instance of AgentChannel. |
format_instructions
Format the instructions.
async format_instructions(kernel: Kernel, arguments: KernelArguments | None = None) -> str | None
Parameters
Name | Description |
---|---|
kernel
Required
|
The kernel instance. |
arguments
Required
|
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 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 StreamingChatMessageContent objects. 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 async get_response(*args, **kwargs) -> ChatMessageContent
invoke
Invoke the agent.
This invocation method will return the intermediate steps and the final results of the agent's execution as a stream of ChatMessageContent objects to the caller.
Note: A ChatMessageContent object contains an entire message.
abstract invoke(*args, **kwargs) -> AsyncIterable[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 a stream of StreamingChatMessageContent objects to the caller.
Note: A StreamingChatMessageContent object contains a chunk of a message.
abstract invoke_stream(*args, **kwargs) -> AsyncIterable[StreamingChatMessageContent]
Attributes
arguments
The arguments for the agent
arguments: KernelArguments | None
channel_type
The type of the agent channel
channel_type: ClassVar[type[AgentChannel] | None] = None
description
The description of the agent
description: str | None
id
The unique identifier of the agent If no id is provided, a new UUID will be generated.
id: str
instructions
The instructions for the agent (optional)
instructions: str | None
kernel
The kernel instance for the agent
kernel: Kernel
name
The name of the agent
name: str
prompt_template
The prompt template for the agent
prompt_template: PromptTemplateBase | None