Tool Invocation

This example shows how to:

  • Register a custom ToolAgent with LocalAgentEngine

  • Define and use a simple Python function as an agent tool

  • Run a complete async test to ensure the FunctionTool works.

1️⃣ Import Dependencies

We first import necessary modules for creating and running the agent engine.

import asyncio
import json
import logging
from agentopera.engine import EVENT_LOGGER_NAME, AgentId, CancellationToken, FunctionCall, LocalAgentEngine
from agentopera.engine.types.models import FunctionExecutionResult
from agentopera.engine.agent.tool_agent import ToolAgent
from agentopera.engine.function_call import FunctionTool

logging.getLogger(EVENT_LOGGER_NAME).setLevel(logging.INFO)

2️⃣ Define the Tool Function

Our agent will execute this simple function when called.

3️⃣ Register ToolAgent and Test

We will now register the agent and send it a FunctionCall to check if it responds as expected.

4️⃣ Run the Test

Now we trigger the async function to test the agent!

Last updated