ChatCompletionAgent Class
A Chat Completion Agent based on ChatCompletionClientBase.
Features marked with this status are nearing completion and are considered stable for most purposes, but may still incur minor refinements or optimizations before achieving full general availability.
Initialize a new instance of ChatCompletionAgent.
Constructor
ChatCompletionAgent(*, arguments: KernelArguments | None = None, description: str | None = None, function_choice_behavior: FunctionChoiceBehavior | None = None, id: str | None = None, instructions: str | None = None, kernel: Kernel | None = None, name: str | None = None, plugins: list[KernelPlugin | object] | dict[str, KernelPlugin | object] | None = None, prompt_template_config: PromptTemplateConfig | None = None, service: ChatCompletionClientBase | None = None)
Parameters
| Name | Description |
|---|---|
|
arguments
Required
|
The kernel arguments for the agent. Invoke method arguments take precedence over the arguments provided here. |
|
description
Required
|
The description of the agent. |
|
function_choice_behavior
Required
|
The function choice behavior to determine how and which plugins are advertised to the model. |
|
kernel
Required
|
The kernel instance. If both a kernel and a service are provided, the service will take precedence if they share the same service_id or ai_model_id. Otherwise if separate, the first AI service registered on the kernel will be used. |
|
id
Required
|
The unique identifier for the agent. If not provided, a unique GUID will be generated. |
|
instructions
Required
|
The instructions for the agent. |
|
name
Required
|
The name of the agent. |
|
plugins
Required
|
The plugins for the agent. If plugins are included along with a kernel, any plugins that already exist in the kernel will be overwritten. |
|
prompt_template_config
Required
|
The prompt template configuration for the agent. |
|
service
Required
|
The chat completion service instance. If a kernel is provided with the same service_id or ai_model_id, the service will take precedence. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
arguments
Required
|
|
|
description
Required
|
|
|
function_choice_behavior
Required
|
|
|
id
Required
|
|
|
instructions
Required
|
|
|
kernel
Required
|
|
|
name
Required
|
|
|
plugins
Required
|
|
|
prompt_template_config
Required
|
|
|
service
Required
|
|
Methods
| configure_service |
Configure the service used by the ChatCompletionAgent. |
| get_response |
Get a response from the agent. |
| invoke |
Invoke the chat history handler. |
| invoke_stream |
Invoke the chat history handler in streaming mode. |
configure_service
Configure the service used by the ChatCompletionAgent.
configure_service() -> ChatCompletionAgent
get_response
Get a response from the agent.
async get_response(history: ChatHistory, arguments: KernelArguments | None = None, kernel: Kernel | None = None, **kwargs: Any) -> ChatMessageContent
Parameters
| Name | Description |
|---|---|
|
history
Required
|
The chat history. |
|
arguments
Required
|
The kernel arguments. (optional) |
|
kernel
Required
|
The kernel instance. (optional) |
|
kwargs
Required
|
The keyword arguments. (optional) |
Returns
| Type | Description |
|---|---|
|
A chat message content. |
invoke
Invoke the chat history handler.
async invoke(history: ChatHistory, arguments: KernelArguments | None = None, kernel: Kernel | None = None, **kwargs: Any) -> AsyncIterable[ChatMessageContent]
Parameters
| Name | Description |
|---|---|
|
history
Required
|
The chat history. |
|
arguments
Required
|
The kernel arguments. |
|
kernel
Required
|
The kernel instance. |
|
kwargs
Required
|
The keyword arguments. |
Returns
| Type | Description |
|---|---|
|
An async iterable of ChatMessageContent. |
invoke_stream
Invoke the chat history handler in streaming mode.
async invoke_stream(history: ChatHistory, arguments: KernelArguments | None = None, kernel: Kernel | None = None, **kwargs: Any) -> AsyncIterable[StreamingChatMessageContent]
Parameters
| Name | Description |
|---|---|
|
history
Required
|
The chat history. |
|
arguments
Required
|
The kernel arguments. |
|
kernel
Required
|
The kernel instance. |
|
kwargs
Required
|
The keyword arguments. |
Returns
| Type | Description |
|---|---|
|
An async generator of StreamingChatMessageContent. |
Attributes
function_choice_behavior
function_choice_behavior: FunctionChoiceBehavior | None
is_release_candidate
is_release_candidate = True
service
service: ChatCompletionClientBase | None
stage_status
stage_status = 'release_candidate'
stage_version
stage_version = '1.22.0-rc1'