Share via


AIPluginProtocol Class

Protocol defining the interface for AI plugins.

AI plugins provide hooks into the message processing pipeline, allowing for custom behavior before/after sending messages, function calls, and system instruction building.

Constructor

AIPluginProtocol(*args, **kwargs)

Methods

on_after_function_call

Called after a function is executed.

on_after_send

Modify response after receiving from model.

on_before_function_call

Called before a function is executed.

on_before_send

Modify input before sending to model.

on_build_functions

Modify the functions array passed to the model.

on_build_instructions

Modify the system message before sending to model.

on_after_function_call

Called after a function is executed.

async on_after_function_call(function_name: str, result: str, args: BaseModel | None = None) -> str | None

Parameters

Name Description
function_name
Required

Name of the function that was called

args

Function arguments that were used, if any.

Default value: None
result
Required

Function execution result

Returns

Type Description

Modified result or None to keep original

on_after_send

Modify response after receiving from model.

async on_after_send(response: ModelMessage) -> ModelMessage | None

Parameters

Name Description
response
Required

Original model response

Returns

Type Description

Modified response or None to keep original

on_before_function_call

Called before a function is executed.

async on_before_function_call(function_name: str, args: BaseModel | None = None) -> None

Parameters

Name Description
function_name
Required

Name of the function being called

args

Validated function arguments, if any.

Default value: None

on_before_send

Modify input before sending to model.

async on_before_send(input: UserMessage | ModelMessage | SystemMessage | FunctionMessage) -> UserMessage | ModelMessage | SystemMessage | FunctionMessage | None

Parameters

Name Description
input
Required

Original input message

Returns

Type Description

Modified message or None to keep original

on_build_functions

Modify the functions array passed to the model.

async on_build_functions(functions: list[microsoft.teams.ai.function.Function[pydantic.main.BaseModel]]) -> list[microsoft.teams.ai.function.Function[pydantic.main.BaseModel]] | None

Parameters

Name Description
functions
Required

Current list of available functions

Returns

Type Description

Modified function list or None to keep original

on_build_instructions

Modify the system message before sending to model.

async on_build_instructions(instructions: SystemMessage | None) -> SystemMessage | None

Parameters

Name Description
instructions
Required

Current system instructions

Returns

Type Description

Modified instructions or None to keep original

Attributes

name

Unique name of the plugin.

Used for identification and debugging purposes.

abstract property name: str

Returns

Type Description

String identifier for this plugin