Skip to main content

langchain-agenttrafficlab

langchain-agenttrafficlab connects a LangChain/LangGraph application to the Agent Traffic Lab (ATL) decision layer. ATL chooses an eligible, executable provider before the adapter loads and runs the provider's MCP tool.

This is a decision integration, not a normal wrapper that exposes atl_decide as an agent tool. The adapter keeps ATL at the provider-selection boundary, validates the returned execution contract, and exposes only the exact tool ATL selected.

Install

python -m pip install langchain-agenttrafficlab

The package supports Python 3.10+ and uses LangChain 1.x, langchain-mcp-adapters 0.3.x, and requests.

Minimal Usage

For v0.1, use the middleware with tools that are already registered on the agent:

from langchain.agents import create_agent
from langchain_agenttrafficlab import ATLMiddleware

agent = create_agent(
    model=model,
    tools=[search_tool, calculator_tool],
    middleware=[ATLMiddleware(timeout=1.5)],
)

ATL can narrow the current registered tool set, but v0.1 does not inject unknown providers or tools.

Dynamic Provider Flow

The v0.2 path is deliberately two-stage. It does not inject a tool into an agent that has already been created:

task
  -> ATL atl_decide
  -> validate executable handoff
  -> connect to the ATL-returned MCP endpoint
  -> load the exact selected tool
  -> create the execution-stage agent
  -> execute
  -> atl_outcome
from langchain_agenttrafficlab import ATLClient, TwoStageATLExecutor

atl = ATLClient(timeout=3.0)
executor = TwoStageATLExecutor(
    decision_client=atl.decide,
    outcome_reporter=atl.report_outcome,
)

result = await executor.run(
    "Extract the title from a public webpage into JSON.",
    model=model,
    original_agent=existing_agent,
)

ATL remains the decision authority. The adapter never hard-codes a fallback provider, maps providers by name or semantic similarity, or treats caller-local tools as ATL candidates. Dynamic loading is limited to ATL-known providers with a validated executable handoff.

Failures And Failover

ATL decision failure may fail open to original_agent when the caller supplies a safe fallback. A malformed, expired, unverifiable, or security-rejected handoff fails closed for dynamic loading. Provider connection or tool-loading failure never substitutes an unverified tool.

Execution errors are preserved and classified using existing ATL outcome fields. For example, HTTP 402 becomes PAYMENT_REQUIRED with failure_type=payment_required and http_status=402. The caller can create retry context from the failed handoff and ask ATL for a fresh decision:

from langchain_agenttrafficlab import TwoStageATLExecutor, classify_execution_error

failure = classify_execution_error(provider_exception)
retry_context = executor.build_retry_context(handoff, failure)
next_handoff = await executor.decide(task, retry_context=retry_context)

ATL chooses any next provider. The adapter validates the new handoff and does not force a particular alternative.

Outcome Reporting

ATLClient.report_outcome preserves the decision reference, outcome correlation token, provider identity, failure code, failure type, HTTP status, and attempt history. For custom reporters, the same payload is available through executor.report_execution_result(handoff, result).

Credentials, if required by the selected provider, must come from an explicit caller-supplied credential provider:

async def credentials_for(handoff):
    return {"Authorization": caller_managed_authorization}

executor = TwoStageATLExecutor(
    decision_client=atl.decide,
    credential_provider=credentials_for,
    outcome_reporter=atl.report_outcome,
)

This package does not invent, persist, or log credentials. Payment and authentication requirements are never bypassed.

Security Model

  • Only validated HTTPS MCP endpoints returned by ATL are used.
  • User or model text cannot override the provider identity, endpoint, transport, or selected tool.
  • Localhost, loopback, private, link-local, reserved, and other non-public endpoint addresses are rejected.
  • The execution-stage agent receives only the exact ATL-selected tool; unrelated tools from the provider are filtered out.
  • Credentials are caller-supplied only and are not persisted or logged by this package.
  • Connection, loading, and execution work is bounded by short timeouts.
  • Provider failures, including payment and auth failures, are reported truthfully and are not silently converted into success.

Limitations

ATL selects from its verified, executable provider universe. This package does not register caller-local providers with ATL, invent provider identities, or claim that a natural-language match is an authorization to connect. Automatic reputation processing and broader fallback policy remain ATL responsibilities.

Development

python -m pip install -e '.[test]'
python -m pytest

License: MIT.

Download files

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

Source Distribution

langchain_agenttrafficlab-0.2.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

langchain_agenttrafficlab-0.2.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_agenttrafficlab-0.2.1.tar.gz.

File metadata

File hashes

Hashes for langchain_agenttrafficlab-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3d676862b63801a7b73cc5970fa5f0f6e700f33a25a0a23f29054b6f5f0a4384
MD5 b8f8b5368408125944d3fd814e9a68e6
BLAKE2b-256 370a5bc50c8e1c80ec334d7db43200e7b8693b4c6b0cd544027a1862bd0b2bf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_agenttrafficlab-0.2.1.tar.gz:

Publisher: publish.yml on wenhua6666668-oss/langchain-agenttrafficlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_agenttrafficlab-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_agenttrafficlab-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc5739278fcb536a5aa7ca060c8645a458fab19e72d58fac10d93a600214305c
MD5 d3a851a95ca58ff1cefe24d68f4eee0d
BLAKE2b-256 e20fcf54ef96f1d9a3372ede589c13c5eee09645b2333c97df9bbe8fc8bef808

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_agenttrafficlab-0.2.1-py3-none-any.whl:

Publisher: publish.yml on wenhua6666668-oss/langchain-agenttrafficlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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