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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_agenttrafficlab-0.2.3.tar.gz.
File metadata
- Download URL: langchain_agenttrafficlab-0.2.3.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29f95c49083ee949c163409cf04181546ea1278a680482866eb5bad564726270
|
|
| MD5 |
785c6b17cb551adc039d535ab97b83ad
|
|
| BLAKE2b-256 |
5e05e7175fffcbf72d5f34ba140af0623e0c46ffc7875d43f1013c760f9b2dcb
|
Provenance
The following attestation bundles were made for langchain_agenttrafficlab-0.2.3.tar.gz:
Publisher:
publish.yml on wenhua6666668-oss/langchain-agenttrafficlab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_agenttrafficlab-0.2.3.tar.gz -
Subject digest:
29f95c49083ee949c163409cf04181546ea1278a680482866eb5bad564726270 - Sigstore transparency entry: 2471631100
- Sigstore integration time:
-
Permalink:
wenhua6666668-oss/langchain-agenttrafficlab@dc188b44a153b55a1a5f84faa48378cdc80764ce -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/wenhua6666668-oss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dc188b44a153b55a1a5f84faa48378cdc80764ce -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_agenttrafficlab-0.2.3-py3-none-any.whl.
File metadata
- Download URL: langchain_agenttrafficlab-0.2.3-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cba7e521ae61c7936c8a3d3daf4358e6c13371258b67aa7f03d1e159296b843
|
|
| MD5 |
f1b4f92904f0c4330b3b4420fb464036
|
|
| BLAKE2b-256 |
8da1abbac8ff30058d850edcceec12fd00010133d83fc3d416aa4395c7d4eca2
|
Provenance
The following attestation bundles were made for langchain_agenttrafficlab-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on wenhua6666668-oss/langchain-agenttrafficlab
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_agenttrafficlab-0.2.3-py3-none-any.whl -
Subject digest:
1cba7e521ae61c7936c8a3d3daf4358e6c13371258b67aa7f03d1e159296b843 - Sigstore transparency entry: 2471631140
- Sigstore integration time:
-
Permalink:
wenhua6666668-oss/langchain-agenttrafficlab@dc188b44a153b55a1a5f84faa48378cdc80764ce -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/wenhua6666668-oss
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dc188b44a153b55a1a5f84faa48378cdc80764ce -
Trigger Event:
release
-
Statement type: