Skip to content

universal-tool-calling-protocol/utcp-agent

Repository files navigation

UTCP Agent

An example implementation of the Universal Tool Calling Protocol (UTCP) that demonstrates how to build an agentic assistant capable of discovering, selecting, and using tools from multiple providers.

Overview

This repository showcases how the Universal Tool Calling Protocol (UTCP) makes agentic tool calling simpler and more powerful. With UTCP, agents can discover and use external tools by interacting with them directly via their native protocols, eliminating the need for custom wrappers around each tool.

The agent can:

  • Load tool providers from configuration files
  • Register new tool providers via natural language instructions
  • Search for the most relevant tools based on user queries
  • Execute tool calls and return results to the user

Getting Started

Prerequisites

  • Python 3.8+
  • OpenAI API key

Installation

  1. Clone this repository
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Create a .env file in the root directory with your OpenAI API key:
    OPENAI_API_KEY=your_api_key_here
    

Running the Agent

Start the agent with:

python main.py

This will:

  1. Start a FastAPI server on http://localhost:1646
  2. Initialize the UTCP client and load providers from providers.json
  3. Start the interactive CLI agent

Using the Agent

The agent supports:

  1. Natural language queries: Ask the agent questions and it will find and use the most relevant tools.
  2. Tool registration: Tell the agent to register a new tool provider by URL or manual specification.

Example interactions:

User: What's the latest news about AI?
Agent: Let me check the latest news for you...
[Agent uses newsapi tool to retrieve information]

User: Register a weather API at https://api.weather.com/utcp
Agent: I'll register this weather API provider for you...
[Agent registers the new provider and confirms]

User: What's the weather in New York?
Agent: Let me check the weather in New York...
[Agent uses newly registered weather API tool]

Tool Provider Configuration

Tool providers are configured in providers.json. Example providers:

[
    {
        "name": "newsapi",
        "provider_type": "text",
        "file_path": "./text_manuals/newsapi_manual.json"
    },
    {
        "name": "utcp_agent",
        "provider_type": "http",
        "http_method": "GET",
        "url": "http://localhost:1646/utcp",
        "content_type": "application/json"
    }
]

Key Components

Core Components

  • Agent (agent.py): Manages conversations with users, searches for relevant tools, and uses OpenAI to generate responses and tool calls.
  • UTCP Client: Handles tool provider registration, tool discovery, and tool execution.

Tool Discovery and Selection

  • EmbeddingModel (embedding_model.py): Local embedding model using all-MiniLM-L6-v2 from HuggingFace for generating vector representations of tools and queries.
  • TagAnalyzer (tag_analyzer.py): Extracts relevant tags from user queries using OpenAI to improve tool search relevance.
  • ToolSelector (tool_selector.py): Implements the UTCP ToolSearchStrategy to find the most appropriate tools based on embedding similarity and tag matching.
  • EmbeddingInMemRepo (vector_store.py): In-memory implementation of the UTCP ToolRepository interface that stores tools and their embeddings.

Server and API

  • FastAPI Server (main.py): Provides endpoints for health checks, the UTCP manual, and registering new HTTP providers.
  • Interactive CLI: Allows users to chat with the agent directly via the command line.

About UTCP

The Universal Tool Calling Protocol (UTCP) is a specification that enables applications to discover and use external tools by interacting with them directly via their native protocols. Key benefits:

  • No wrapper tax: Call any tool without changes to the tool itself
  • Native security: Leverage existing security mechanisms
  • Scalable: Handle a large number of tools and calls
  • Simple: Easy to implement and use

For more information about UTCP, visit the UTCP documentation.

License

Apache License 2.0

About

Making tool usage easy using utcp

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages