LangChain Agent Protocol Python Bindings

raw JSON →
0.0.15 verified Sat May 09 auth: no python

Python client bindings for the LangChain agent streaming protocol. Provides a client to interact with remote agents following the protocol specification. Version 0.0.15 supports Python >=3.10, <4.0. New releases are frequent (multiple per month) with backward-incompatible changes expected.

pip install langchain-protocol
error ModuleNotFoundError: No module named 'langchain.protocol'
cause Incorrect import path; the package is 'langchain-protocol' but the module is 'langchain_protocol'.
fix
Use 'from langchain_protocol import Client'
error TypeError: Client.__init__() got an unexpected keyword argument 'base_url'
cause Client constructor uses 'url' not 'base_url'. Common mistake from other HTTP clients.
fix
Use Client(url='http://...') instead of Client(base_url='http://...')
error KeyError: 'run_id'
cause The response schema changed between versions. For example, runs.wait() may return a different structure.
fix
Check the response object keys (e.g., 'id' instead of 'run_id' in some versions) and pin the protocol version.
gotcha The Client constructor expects a 'url' argument (not 'base_url'). Using 'base_url' may silently fall back to default.
fix Use client = Client(url='...')
breaking The package version follows the protocol spec versioning, not semantic versioning. Minor increments (0.1.x -> 0.2.0) may include breaking API changes.
fix Always pin a specific version and consult the changelog before upgrading.
deprecated The 'runs.create' endpoint moved from /threads/{tid}/runs to /runs in version 0.2.0. Old path is deprecated.
fix Use client.runs.create() without thread_id argument for stateless runs, or pass thread_id as argument.
gotcha Authentication headers must be passed as dict to the Client constructor. The library does not read environment variables automatically.
fix Explicitly pass headers={'Authorization': 'Bearer <token>'} on client creation.

Creates a client and performs a simple agent interaction.

import os
from langchain_protocol import Client

client = Client(
    url=os.environ.get("PROTOCOL_URL", "http://localhost:8000"),
    headers={"Authorization": f"Bearer {os.environ.get('PROTOCOL_API_KEY', '')}"}
)

# List available agents
agents = client.agents.search()
print(agents)

# Create a thread and run
thread = client.threads.create()
run = client.runs.create(
    thread_id=thread["thread_id"],
    agent_id=agents[0]["agent_id"],
    input={"messages": [{"role": "user", "content": "Hello"}]}
)
print(run)

# Stream results
for event in client.runs.stream(thread["thread_id"], run["run_id"]):
    print(event)