Skip to main content

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

Metadata

Release files for clarvia-langchain 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clarvia-langchain 0.1.0
File Size Uploaded Provenance
clarvia_langchain-0.1.0.tar.gz 9.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for clarvia-langchain 0.1.0
File Interpreter ABI Platform
clarvia_langchain-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.6 kB

Release files / clarvia_langchain-0.1.0.tar.gz

Download URL clarvia_langchain-0.1.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7eb86463ae671f058904ab47810095fcd96ca8115072a51e3f1087c4aec8b0ed
BLAKE2b-256 checksum
How to use checksums
d7f21a0451942030642f97d5684aace398885f1e7fb4b6ac01c4bb047cab85e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / clarvia_langchain-0.1.0-py3-none-any.whl

Download URL clarvia_langchain-0.1.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
372fcd756cfe984c73440e6d0f6f1d2cbfa11d173f1814d3c1e5755e42d00ff7
BLAKE2b-256 checksum
How to use checksums
c58508a97ffc5b4ab074541b8cd7daf7d69e592ecdcaf6e642353341ada6612b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for clarvia-langchain 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page