Skip to content

ClientTool

autogen.beta.tools.final.client_tool.ClientTool #

ClientTool(schema)

Bases: Tool

Source code in autogen/beta/tools/final/client_tool.py
def __init__(self, schema: dict[str, Any]) -> None:
    self.schema = FunctionToolSchema.from_dict(schema)

schema instance-attribute #

schema = from_dict(schema)

schemas async #

schemas(context)
Source code in autogen/beta/tools/final/client_tool.py
async def schemas(self, context: "Context") -> list[FunctionToolSchema]:
    return [self.schema]

register #

register(stack, context, *, middleware=())
Source code in autogen/beta/tools/final/client_tool.py
def register(
    self,
    stack: "ExitStack",
    context: "Context",
    *,
    middleware: Iterable["BaseMiddleware"] = (),
) -> None:
    execution: ToolExecution = self
    for mw in middleware:
        execution = partial(mw.on_tool_execution, execution)

    async def execute(event: "ToolCall", context: "Context") -> None:
        result = await execution(event, context)
        await context.send(result)

    stack.enter_context(
        context.stream.where((ToolCall.name == self.schema.function.name) & ClientToolCall.not_()).sub_scope(
            execute
        ),
    )