Skip to main content

Toolkit for normalizing Agent Protocol (Agent2Agent) communication.

Project description

ai_agents_bridge

ai_agents_bridge now focuses on a single goal: normalize Agent2Agent (A2A) / Agent Protocol communication so any application can talk to any remote agent without learning a custom payload shape.

What's included

  • AgentProtocolAdapter – HTTP client that speaks /v1/exchange in the Agent Protocol format.
  • Server helperscreate_lambda_handler, create_fastapi_router, and friends with protocol="agent_protocol" so you can expose an agent quickly. FastAPI/Flask helpers auto-register themselves on an existing app when detected, so you rarely need to spin up a new server.
  • Shared modelsAgentMessage, BaseAgent, and a registry-backed AgentFactory so future adapters can be re‑added without redesigning the package.
  • Schema registry loader – fetch schema manifests from GitHub/S3/local paths and auto-wire schema adapters for apps that need bespoke payloads.
  • Secrets-aware configConfigManager fetches configuration values from AWS Secrets Manager or environment variables, used by the examples to drive ports and API keys.
  • Lean tests & workflows – only the pieces that validate the Agent Protocol surface remain.

If you need to add more adapters later, the factory, base classes, and docs under docs/ADDING_PROVIDERS.md describe how to plug them back in.

Installation

pip install .
# or
pip install -e .[dev]

Quick start

Call a remote Agent Protocol service

from ai_agents_bridge import AgentFactory

agent = AgentFactory.create(
    "agent_protocol",
    base_url="https://agent.example.com",
    api_key="optional-bearer-token",
)

response = agent.send("Draft a Jira rollout plan")
print(response.content)
print(response.metadata)

Expose your agent with Agent Protocol schema

from typing import List

from fastapi import FastAPI

from ai_agents_bridge import AgentMessage
from ai_agents_bridge.server import (
    create_fastapi_router,
    create_lambda_handler,
)

def integrations_agent(messages: List[AgentMessage]) -> str:
    prompt = messages[-1].content
    return f"Answering integrations question: {prompt}"

lambda_handler = create_lambda_handler(
    integrations_agent,
    protocol="agent_protocol",
    default_metadata={"agent": "integrations"},
)

# FastAPI auto-registration detects the existing `app` variable.
app = FastAPI()
router = create_fastapi_router(
    integrations_agent,
    protocol="agent_protocol",
    route_path="/agent/exchange",
)
if not getattr(router, "_a2a_auto_registered", False):
    app.include_router(router)

The same protocol="agent_protocol" flag works with the FastAPI and Flask helpers so you can expose /agent/exchange over HTTP.

Reuse an existing FastAPI/Flask server

When the SDK spots a module-level app/application (or you explicitly provide one), it auto-registers the Agent Protocol endpoint:

  • create_fastapi_router(...) calls include_router(...).
  • create_flask_handler(...) calls add_url_rule(...).

Environment overrides:

  • A2A_FASTAPI_APP=package.module:app forces a specific FastAPI app.
  • A2A_FLASK_APP=package.module:application forces a specific Flask app.
  • Set either variable to skip, off, 0, etc. to disable auto-detection.

If no app is found the helpers still return the router/handler, so you can register them manually (as before).

Configure the Agent Protocol server port

The examples/expose_agent_agentprotocol.py FastAPI app reads its port from AGENT_PROTOCOL_PORT. Values come from AWS Secrets Manager when AGENT_PROTOCOL_SECRET_NAME is set, otherwise they fall back to local environment variables:

export AGENT_PROTOCOL_SECRET_NAME="a2a/server/config"
# secret JSON must include {"AGENT_PROTOCOL_PORT": "8005"}
python examples/expose_agent_agentprotocol.py

ConfigManager drives this behavior and is available for your own settings as well:

from ai_agents_bridge.config import ConfigManager

config = ConfigManager(secret_name="a2a/server/config")
api_key = config.get("AGENT_PROTOCOL_API_KEY")

Multiple agents, same protocol

Instantiate as many AgentProtocolAdapter clients as you need—point them at different base_url values or reuse the same remote agent from different apps. AgentFactory keeps the registration hooks required for future adapter expansion.

Docs & diagrams

Running tests

pip install -r requirements-dev.txt
pytest -v

The suite now focuses on:

  • tests/test_agent_protocol_adapter.py
  • tests/test_server.py
  • tests/test_models.py
  • tests/test_factory.py
  • tests/test_config.py

GitHub Actions (.github/workflows/test.yml) runs these tests on every push and pull request, and .github/workflows/agent_protocol_e2e.yml spins up the sample FastAPI server to exercise the adapter end-to-end.

Extending later

Even though the repository now ships only the Agent Protocol adapter, the core scaffolding (base classes, registry, config helpers, packaging) stays intact. Follow docs/ADDING_PROVIDERS.md whenever you want to add another adapter, register new providers with AgentFactory, and reintroduce their tests/docs incrementally.

License

MIT – see LICENSE.

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

any_agent2agent-0.0.1.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

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

any_agent2agent-0.0.1-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file any_agent2agent-0.0.1.tar.gz.

File metadata

  • Download URL: any_agent2agent-0.0.1.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for any_agent2agent-0.0.1.tar.gz
Algorithm Hash digest
SHA256 da1aed6539d432449b7636b61f4987f30efad114b2f02728f9f1edbc3c72df18
MD5 645ad332fb3f27eb43d953f36ee3329b
BLAKE2b-256 b5e382ba5c15b7c0757294c8697f498257b768e53456e04d0155ec2975bb9b72

See more details on using hashes here.

File details

Details for the file any_agent2agent-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for any_agent2agent-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32abe38141e8d041752121262800fed2427f7ff3040bff83ba7d02c619f131b8
MD5 c6bc9472fd9aa2fcf37a1bb123791c13
BLAKE2b-256 deb4429181821a9b5dcc50b705a8979e013a3425d3e2c5e24f96d53974ec7284

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