Agent with Multiple Tools

Learn ho to create an agent that uses multiple tools.

A Support Agent with a RAG Tool and multiple Function Tools

This example demonstrates an agent equipped with a knowledge base (using AgenticRagTool) and a collection of custom function tools (using Toolkit).

Before you start, create a knowledge base for the RAG tool. See Creating a Knowledge Base. For the data source, create an Object Storage file. Then, copy the OCID of the knowledge base and paste it in a notepad.

product_support_agent.py

from oci.addons.adk import Agent, AgentClient
from oci.addons.adk.tool.prebuilt import AgenticRagTool
from custom_function_tools import AccountToolkit

def main():

    # Assuming the resources were already provisioned
    agent_endpoint_id = "ocid1.genaiagentendpoint..."
    knowledge_base_id = "ocid1.genaiagentknowledgebase..."

    client = AgentClient(
        auth_type="api_key",
        profile="DEFAULT",
        region="us-chicago-1"
    )

    instructions = """
    You are customer support agent.
    Use RAG tool to answer product questions.
    Use function tools to fetch user and org info by id.
    Only orgs of Enterprise plan can use Responses API.
    """

    agent = Agent(
        client=client,
        agent_endpoint_id=agent_endpoint_id,
        instructions=instructions,
        tools=[
            AgenticRagTool(knowledge_base_ids=[knowledge_base_id]),
            AccountToolkit()
        ]
    )

    agent.setup()

    # This is a context your existing code is best at producing (e.g., fetching the authenticated user id)
    client_provided_context = "[Context: The logged in user ID is: user_123] "

    # Handle the first user turn of the conversation
    input = "What is the Responses API?"
    input = client_provided_context + " " + input
    response = agent.run(input)
    response.pretty_print()

    # Handle the second user turn of the conversation
    input = "Is my user account eligible for the Responses API?"
    input = client_provided_context + " " + input
    response = agent.run(input, session_id=response.session_id)
    response.pretty_print()


if __name__ == "__main__":
    main()

Info: This example also shows multi-turn conversation handling using session_id to maintain context between turns. Explore more about multi-turn conversation handling example.


The agent uses a custom AccountToolkit. You can create your own custom toolkit class by inheriting from oci.addons.adk, the Toolkit class.

A Toolkit class helps you organize related tools into a single class.

You can reuse the same toolkit in different agents. You can also maintain some state inside the instance of the Toolkit class. The ADK invokes the instance method so your state is available to the methods with the @tool decorator.

custom_function_tools.py

from typing import Dict, Any
from oci.addons.adk import Toolkit, tool

class AccountToolkit(Toolkit):

    @tool
    def get_user_info(self, user_id: str) -> Dict[str, Any]:
        """Get information about a user by user_id

        Args:
            user_id (str): The user ID to get information about

        Returns:
            Dict[str, Any]: A dictionary containing the user information
        """
        # Here is a mock implementation
        return {
            "user_id": user_id,
            "account_id": "acc_111",
            "name": "John Doe",
            "email": "john.doe@example.com",
            "org_id": "org_222",
        }

    @tool
    def get_org_info(self, org_id: str) -> Dict[str, Any]:
        """Get information about an organization by org_id

        Args:
            org_id (str): The organization ID to get information about

        Returns:
            Dict[str, Any]: A dictionary containing the organization information
        """
        # Here is a mock implementation
        return {
            "org_id": org_id,
            "name": "Acme Inc",
            "admin_email": "admin@acme.com",
            "plan": "Enterprise",
        }