LangChain integration for Clarvia AEO scoring - gate external API calls based on agent-friendliness
Project description
clarvia-langchain
LangChain integration for Clarvia AEO (Agent Experience Optimization) scoring. Gate your LangChain tool calls based on how agent-friendly the target service is.
Installation
pip install clarvia-langchain
Quick Start
from clarvia_langchain import CriteriaGate, GatedTool
from langchain_community.tools import SerpAPIWrapper
# 1. Create a gate with your Clarvia API key
gate = CriteriaGate(
api_key="clv_xxx",
min_rating="AGENT_FRIENDLY", # Block services scoring below 70
)
# 2. Wrap any LangChain tool
search = SerpAPIWrapper()
gated_search = GatedTool(
tool=search,
gate=gate,
service_url="https://serpapi.com",
)
# 3. Use normally — the gate checks AEO score before each call
result = gated_search.invoke({"query": "latest AI news"})
Rating Tiers
| Rating | Score | Meaning |
|---|---|---|
AGENT_NATIVE |
90-100 | Fully optimized for AI agents |
AGENT_FRIENDLY |
70-89 | Usable by agents with minor friction |
AGENT_POSSIBLE |
50-69 | Partially usable, may have issues |
AGENT_HOSTILE |
0-49 | Actively hostile or unusable by agents |
Configuration
gate = CriteriaGate(
api_key="clv_xxx",
min_rating="AGENT_FRIENDLY", # or ServiceRating enum
cache_ttl=3600, # Cache scores for 1 hour (default)
timeout=10.0, # HTTP timeout in seconds
)
Handling Blocked Calls
from clarvia_langchain import GatedTool, GateBlockedError
# Option 1: Raise on block (default)
gated = GatedTool(tool=my_tool, gate=gate, service_url="...")
try:
result = gated.invoke({"query": "test"})
except GateBlockedError as e:
print(f"Blocked: {e.gate_result.reason}")
print(f"Try these instead: {e.gate_result.alternatives}")
# Option 2: Return error string (for agent consumption)
gated = GatedTool(
tool=my_tool, gate=gate,
service_url="...",
raise_on_block=False,
)
result = gated.invoke({"query": "test"})
# result = "BLOCKED: ... | Alternatives: ..."
Direct Gate Usage
gate = CriteriaGate(api_key="clv_xxx")
result = gate.check("https://some-api.com")
print(result.allowed) # True/False
print(result.score) # 0-100
print(result.rating) # ServiceRating enum
print(result.alternatives) # List of suggested alternatives
CrewAI Integration
clarvia-langchain works with any LangChain-compatible framework, including CrewAI.
from crewai import Agent, Task, Crew
from crewai_tools import SerperDevTool
from clarvia_langchain import CriteriaGate, GatedTool
# 1. Set up the gate
gate = CriteriaGate(api_key="clv_xxx", min_rating="AGENT_FRIENDLY")
# 2. Wrap any CrewAI-compatible tool
search = SerperDevTool()
gated_search = GatedTool(
tool=search,
gate=gate,
service_url="https://serper.dev",
)
# 3. Use with CrewAI agents
researcher = Agent(
role="Research Analyst",
goal="Find reliable data from agent-friendly sources",
tools=[gated_search],
)
task = Task(
description="Research the latest trends in AI agent tooling",
agent=researcher,
expected_output="A summary of key trends",
)
crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
The gate transparently checks AEO scores before each tool call. If a service scores below the threshold, the agent receives a structured error with suggested alternatives, allowing it to adapt its strategy.
API Behavior
- Caching: Scores are cached in-memory with a 1-hour TTL by default. Use
gate.clear_cache()to reset. - Fallback: If the Clarvia API is unreachable, calls are allowed through with a warning log (fail-open).
- Async: Both sync and async paths are supported (
gate.check()/gate.acheck()).
Development
pip install -e ".[dev]"
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
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 clarvia_langchain-0.1.0.tar.gz.
File metadata
- Download URL: clarvia_langchain-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb86463ae671f058904ab47810095fcd96ca8115072a51e3f1087c4aec8b0ed
|
|
| MD5 |
ce47244d94f375e61524aab3214e0215
|
|
| BLAKE2b-256 |
d7f21a0451942030642f97d5684aace398885f1e7fb4b6ac01c4bb047cab85e3
|
File details
Details for the file clarvia_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clarvia_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
372fcd756cfe984c73440e6d0f6f1d2cbfa11d173f1814d3c1e5755e42d00ff7
|
|
| MD5 |
79aa4d9111fb21839edadf43b6e2de12
|
|
| BLAKE2b-256 |
c58508a97ffc5b4ab074541b8cd7daf7d69e592ecdcaf6e642353341ada6612b
|