Skip to main content

LangChain-native equivalent of Google ADK's RemoteA2aAgent — invoke remote A2A agents as LangChain Runnables and tools

Project description

langchain-remote-a2a-agent

PyPI License Python

LangChain-native equivalent of Google ADK's RemoteA2aAgent. Wraps any Agent2Agent (A2A) protocol server as a LangChain Runnable, so a remote agent can be .invoke()d, .astream()ed, dropped into a create_agent/LangGraph pipeline as a node, or exposed to another agent as a callable tool via .as_tool() — the same interface you'd use for any local LangChain component.

This is useful when the agent doing the actual work runs as a separate service (different language, different team, different deployment) and you want to compose it into a LangChain-orchestrated system without hand-rolling the A2A JSON-RPC/SSE client plumbing yourself.

Install

pip install langchain-remote-a2a-agent

Requires Python 3.11+. Ships a py.typed marker — type checkers (mypy, Pyright) and IDE autocomplete/hover (VS Code + Pylance) pick up the inline type hints and docstrings automatically once installed.

Quickstart

from langchain_remote_a2a_agent import RemoteAgent

research = RemoteAgent(
    name="research",
    description="Research agent",
    agent_card_url="http://localhost:8001/.well-known/agent-card.json",
)

result = research.invoke("What is the boiling point of nitrogen?")
print(result["messages"][-1].content)

Multi-turn conversations

Pass a thread_id to resume the same server-side A2A context across calls:

from langchain_core.runnables import RunnableConfig

config = RunnableConfig(configurable={"thread_id": "user-42"})

result1 = research.invoke("Tell me about black holes.", config)
result2 = research.invoke("How do they emit Hawking radiation?", config)

Streaming

async for chunk in research.astream("Explain quantum entanglement."):
    if chunk.get("messages"):
        msg = chunk["messages"][-1]
        if reasoning := msg.additional_kwargs.get("reasoning_content"):
            print(f"[reasoning] {reasoning}")
        elif msg.content:
            print(msg.content, end="", flush=True)

As a tool inside a LangChain agent

from langchain.agents import create_agent

supervisor = create_agent(
    model="openai:gpt-5",
    tools=[research.as_tool()],
)

More examples

Nine complete, runnable examples — synchronous/async invocation, multi-turn state, streaming with reasoning traces, create_agent integration, LangGraph node usage, concurrent batching, bearer-token auth, and agent-card inspection — live in langchain_remote_a2a_agent/examples.py. They're also directly importable for reference:

from langchain_remote_a2a_agent import examples

API surface

Export What it is
RemoteAgent The main Runnable — wraps a remote A2A agent.
RemoteAgent.as_tool() Returns a BaseTool for use inside another agent's tool list.
RemoteAgent.reset_thread() Clears the stored context_id for a thread_id, starting a fresh server-side conversation.
RemoteAgent.thread_state() JSON-serialisable snapshot of a thread's tracked state.
RemoteAgent.aget_agent_card() Fetch (or return cached) the remote agent's Agent Card.
RemoteAgent.aget_extended_agent_card() Fetch the remote agent's Extended Agent Card.
ThreadState, ConversationStateStore The conversation-state tracking types, exposed for custom store implementations.
RemoteAgentError and subclasses CardResolutionError, A2AProtocolError, A2ATimeoutError, A2AAuthError, A2AStreamError, InputNormalisationError — catch these individually or RemoteAgentError for all of them.

Agent Card Inspection

You can inspect the capabilities, skills, security requirements, and metadata of the remote agent by fetching its Agent Card:

Public Agent Card

The Public Agent Card is resolved from the agent card URL when the agent is first initialized:

# Fetch (or return cached) the public agent card
card = await research.aget_agent_card()

print("Agent name:", card.name)
print("Description:", card.description)
print("Skills:", card.skills)

Extended Agent Card

If the remote agent supports an extended card (carrying additional metadata or developer-defined parameters that might require auth/permissions), you can fetch it using aget_extended_agent_card():

# Fetch the extended agent card from the remote server
extended_card = await research.aget_extended_agent_card()

print("Developer info:", extended_card.provider.organization)
print("Extended capabilities:", extended_card.capabilities)

Github Repo

LangChain Remote A2A Agent

Tests

# Run against a live agent
pytest tests/test_integration.py -v --agent-url http://localhost:8001/.well-known/agent-card.json

# With auth token for extended card
pytest tests/test_integration.py -v \
  --agent-url http://localhost:8001/.well-known/agent-card.json \
  --auth-token "Bearer sk-..."

# Custom test query
pytest tests/test_integration.py -v \
  --agent-url http://localhost:8001/.well-known/agent-card.json \
  --test-query "Summarize quantum computing"

License

Apache License 2.0 — 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

langchain_remote_a2a_agent-1.0.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

langchain_remote_a2a_agent-1.0.0-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_remote_a2a_agent-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_remote_a2a_agent-1.0.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for langchain_remote_a2a_agent-1.0.0.tar.gz
Algorithm Hash digest
SHA256 921844f825d074e335fcc510167e55c3e8a2ed3bd5f736e191ab3281c3e8db36
MD5 23bee73c7e284aa76078dc16cc96d782
BLAKE2b-256 f4ea7d689a462f7073f549bb68e54c80437bffd8cf8f8fb90db79612974238dd

See more details on using hashes here.

File details

Details for the file langchain_remote_a2a_agent-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_remote_a2a_agent-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for langchain_remote_a2a_agent-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ffcc1350243e444f8050731b85655c7ef8f3ec61c7335d831b3dfff2be0c1c1
MD5 60483d6359021048aeff8996476caf36
BLAKE2b-256 be36756bc72ca55647f916b8a9ed9a9e1b915b5e0deaf47066c3d54d3b856da6

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