次の方法で共有


ChatCompletionAgent Class

A KernelAgent specialization based on ChatCompletionClientBase.

Note: enable function_choice_behavior on the PromptExecutionSettings to enable function choice behavior which allows the kernel to utilize plugins and functions registered in the kernel.

Note: This class is experimental and may change in the future.

Initialize a new instance of ChatCompletionAgent.

Inheritance
ChatCompletionAgent

Constructor

ChatCompletionAgent(service_id: str | None = None, kernel: Kernel | None = None, name: str | None = None, id: str | None = None, description: str | None = None, instructions: str | None = None, execution_settings: PromptExecutionSettings | None = None)

Parameters

Name Description
service_id

The service id for the chat completion service. (optional) If not provided, the default service name default will be used.

Default value: None
kernel

The kernel instance. (optional)

Default value: None
name

The name of the agent. (optional)

Default value: None
id

The unique identifier for the agent. (optional) If not provided, a unique GUID will be generated.

Default value: None
description

The description of the agent. (optional)

Default value: None
instructions

The instructions for the agent. (optional)

Default value: None
execution_settings

The execution settings for the agent. (optional)

Default value: None

Methods

invoke

Invoke the chat history handler.

invoke_stream

Invoke the chat history handler in streaming mode.

invoke

Invoke the chat history handler.

async invoke(history: ChatHistory) -> AsyncIterable[ChatMessageContent]

Parameters

Name Description
kernel
Required

The kernel instance.

history
Required

The chat history.

Returns

Type Description

An async iterable of ChatMessageContent.

invoke_stream

Invoke the chat history handler in streaming mode.

async invoke_stream(history: ChatHistory) -> AsyncIterable[StreamingChatMessageContent]

Parameters

Name Description
kernel
Required

The kernel instance.

history
Required

The chat history.

Returns

Type Description

An async generator of StreamingChatMessageContent.

Attributes

model_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'populate_by_name': True, 'validate_assignment': True}

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.fields from Pydantic V1.

model_fields: ClassVar[Dict[str, FieldInfo]] = {'description': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'execution_settings': FieldInfo(annotation=Union[PromptExecutionSettings, NoneType], required=False, default=None), 'id': FieldInfo(annotation=str, required=False, default_factory=<lambda>), 'instructions': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'kernel': FieldInfo(annotation=Kernel, required=False, default_factory=Kernel), 'name': FieldInfo(annotation=str, required=False, default_factory=<lambda>), 'service_id': FieldInfo(annotation=str, required=True)}

description

description: str | None

execution_settings

execution_settings: PromptExecutionSettings | None

id

id: str

instructions

instructions: str | None

is_experimental

is_experimental = True

kernel

kernel: Kernel

name

name: str

service_id

service_id: str