Skip to content

register_function

autogen.register_function #

register_function(f, *, caller, executor, name=None, description)

Register a function to be proposed by an agent and executed for an executor.

This function can be used instead of function decorators @ConversationAgent.register_for_llm and @ConversationAgent.register_for_execution.

PARAMETER DESCRIPTION
f

the function to be registered.

TYPE: Callable[..., Any]

caller

the agent calling the function, typically an instance of ConversableAgent.

TYPE: ConversableAgent

executor

the agent executing the function, typically an instance of UserProxy.

TYPE: ConversableAgent

name

name of the function. If None, the function name will be used (default: None).

TYPE: Optional[str] DEFAULT: None

description

description of the function. The description is used by LLM to decode whether the function is called. Make sure the description is properly describing what the function does or it might not be called by LLM when needed.

TYPE: str

Source code in autogen/agentchat/conversable_agent.py
@export_module("autogen")
def register_function(
    f: Callable[..., Any],
    *,
    caller: ConversableAgent,
    executor: ConversableAgent,
    name: Optional[str] = None,
    description: str,
) -> None:
    """Register a function to be proposed by an agent and executed for an executor.

    This function can be used instead of function decorators `@ConversationAgent.register_for_llm` and
    `@ConversationAgent.register_for_execution`.

    Args:
        f: the function to be registered.
        caller: the agent calling the function, typically an instance of ConversableAgent.
        executor: the agent executing the function, typically an instance of UserProxy.
        name: name of the function. If None, the function name will be used (default: None).
        description: description of the function. The description is used by LLM to decode whether the function
            is called. Make sure the description is properly describing what the function does or it might not be
            called by LLM when needed.

    """
    f = caller.register_for_llm(name=name, description=description)(f)
    executor.register_for_execution(name=name)(f)