Skip to main content

A lightweight framework to expose any API as an agent-compatible tool

Project description

B2A Toolkit 🚀

A lightweight framework to expose any API as an agent-compatible tool. B2A Toolkit makes it easy to create tools that can be used by AI agents, with built-in support for OpenAI's MCP spec, LangChain, and CrewAI.

Features

Current Capabilities ✅

  • Tool Definition

    • Simple decorator-based API
    • Input/output validation
    • Type checking and conversion
    • Built-in documentation support
  • Tool Server

    • Local HTTP server for tool execution
    • Automatic manifest generation
    • RESTful endpoints for tool invocation
    • Built-in validation and error handling
  • Authentication

    • OAuth support
    • API key support
    • Configurable scopes
    • Optional auth requirements
  • Framework Support

    • OpenAI MCP spec compatibility
    • LangChain tool format
    • CrewAI integration
  • Tool Observability 🔍

    • Per-call logging with unique IDs
    • Real-time log streaming
    • Web dashboard for monitoring
    • Usage analytics and debugging

Installation

pip install b2a-toolkit

Quick Start

  1. Define a tool using the @define_tool decorator:
from toolkit import define_tool, ToolAuth

@define_tool(
    name="create_expense",
    description="Creates an expense in the system",
    inputs={
        "amount": "number",
        "category": "string",
        "description": "string",
        "date": "string"
    },
    output_type="object",
    output_description="The created expense object",
    auth=ToolAuth(
        type="oauth",
        required=True,
        scopes=["expenses:write"]
    )
)
def create_expense(amount: float, category: str, description: str, date: str):
    # Your implementation here
    return {"id": "exp_123", "amount": amount, ...}
  1. Build the tool manifest:
toolkit build examples/expense_tool.py -o manifest.json
  1. Test your tool:
toolkit test create_expense examples/expense_tool.py
  1. Start the tool server:
toolkit serve examples/expense_tool.py

This starts a local server with:

  • GET /manifest.json - Get tool definitions
  • POST /run/<tool_name> - Execute a tool
  1. Monitor your tools:
# View recent tool calls
toolkit logs --limit 10

# Follow logs in real-time
toolkit logs --follow

# Filter logs for specific tool
toolkit logs --tool create_expense

# Launch web dashboard
toolkit dashboard

Tool Definition

The @define_tool decorator takes the following parameters:

  • name: Name of the tool
  • description: Description of what the tool does
  • inputs: Dictionary mapping input parameter names to their types
  • output_type: Type of the tool's output
  • output_description: Description of the tool's output
  • auth: Optional authentication configuration
  • version: Version of the tool (default: "0.1.0")
  • tags: Optional list of tags/categories

CLI Commands

Build Manifest

toolkit build <module_path> [--output <output_file>] [--format <json|openapi>]

Start Server

toolkit serve <module_path> [--host HOST] [--port PORT]

Test Tool

toolkit test <tool_name> <module_path>

View Logs

# View recent logs
toolkit logs [--tool TOOL_NAME] [--limit N] [--format text|json]

# Follow logs in real-time
toolkit logs --follow

# Inspect specific tool usage
toolkit inspect TOOL_NAME --last 5

Launch Dashboard

toolkit dashboard [--host HOST] [--port PORT]

Examples

Check out the examples/ directory for more examples:

  • expense_tool.py: A simple expense creation tool
  • More examples coming soon...

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b2a_toolkit-0.1.2.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b2a_toolkit-0.1.2-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file b2a_toolkit-0.1.2.tar.gz.

File metadata

  • Download URL: b2a_toolkit-0.1.2.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for b2a_toolkit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5d2d01d8daf33f40b8bc1d0e0e1c72d826b0745be918a6115ab71ab506fd2218
MD5 cd66144e7489c63c027ac57468fbd70b
BLAKE2b-256 43b238e856744604d39f7df26f12a5d02d2bebe8465350697891ea57a19c63bb

See more details on using hashes here.

File details

Details for the file b2a_toolkit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: b2a_toolkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for b2a_toolkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7285676dda40784ade22ec6844daf6db190d4b8305c400c5b173dde3f58052
MD5 8d5cd2995f0d78571f2ff7055d31b22c
BLAKE2b-256 6f994a0beee5d5e1adb109f038fbd61e9871edba6fc6f6d703fed54d34212f67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page