Skip to main content

Never let your AI agent fail again โ€” automatic fallback to AgentClear's marketplace of 60+ API services.

Project description

๐Ÿ›ก๏ธ agentclear-fallback โ€” Never Let Your Agent Fail Again

Your agent crashes when it doesn't have the right tool. This package catches those failures and automatically discovers, pays for, and calls the right API through AgentClear's marketplace of 60+ services.

One line of code turns every broken agent into a capable one.

pip install agentclear-fallback

Quick Start

from agentclear_fallback import agentclear_fallback

@agentclear_fallback(intent="get weather data")
def get_weather(city: str):
    raise NotImplementedError("No weather API configured")

# Instead of crashing, this discovers a weather API on AgentClear,
# calls it, and returns the data:
result = get_weather("London")
print(result)  # {"temperature": 15, "condition": "Cloudy", ...}

Set your API key:

export AGENTCLEAR_API_KEY="your-key-here"

Get your key โ†’ agentclear.dev/settings/api-keys


How It Works

Your function raises an exception
         โ”‚
         โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚  Intercept   โ”‚  The decorator catches the error
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚  Discover    โ”‚  POST /api/discover โ†’ finds the right service
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚  Call        โ”‚  POST /api/proxy/{service_id} โ†’ invokes the API
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚  Return      โ”‚  Response flows back as if the function worked
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

No configuration. No manual API integration. Just describe what you need.


Decorator Usage

Explicit intent

@agentclear_fallback(intent="translate text between languages")
def translate(text: str, target_language: str):
    raise NotImplementedError()

result = translate("Hello!", target_language="fr")

Auto-inferred intent

The intent is derived from the function name and docstring:

@agentclear_fallback
def fetch_stock_price(ticker: str):
    """Look up the current stock price for a given ticker symbol."""
    raise NotImplementedError()

result = fetch_stock_price("AAPL")

Catch specific exceptions only

@agentclear_fallback(catch=(NotImplementedError, ConnectionError))
def get_data(query: str):
    raise NotImplementedError()

Async support

@agentclear_fallback(intent="geocode address")
async def geocode(address: str):
    raise NotImplementedError()

result = await geocode("1600 Amphitheatre Parkway")

LangChain Integration

Add AgentClearFallbackTool as the last tool in your agent. When the LLM can't find a matching tool, it falls through to AgentClear:

pip install "agentclear-fallback[langchain]"
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from agentclear_fallback import AgentClearFallbackTool

llm = ChatOpenAI(model="gpt-4o")

tools = [
    # ... your existing tools ...
    AgentClearFallbackTool(),  # โ† always last
]

agent = initialize_agent(tools, llm, agent=AgentType.OPENAI_FUNCTIONS)

# The calculator tool handles this:
agent.invoke({"input": "What is 42 * 17?"})

# No weather tool? AgentClear handles it:
agent.invoke({"input": "What's the weather in Tokyo?"})

The tool's description is carefully crafted so the LLM knows to use it as a last resort for any API-backed task.


AutoGen Integration

pip install "agentclear-fallback[autogen]"
from autogen import ConversableAgent
from agentclear_fallback import get_agentclear_autogen_tool

tool = get_agentclear_autogen_tool()

assistant = ConversableAgent("assistant", llm_config={...})
user_proxy = ConversableAgent("user_proxy", human_input_mode="NEVER")

# Register the tool
assistant.register_for_llm(
    name=tool["name"],
    description=tool["description"],
)(tool["func"])

user_proxy.register_for_execution(name=tool["name"])(tool["func"])

user_proxy.initiate_chat(assistant, message="What's the weather in Tokyo?")

Core API

For direct usage without decorators or agent frameworks:

from agentclear_fallback import AgentClearFallback

client = AgentClearFallback()

# Discover + call in one step
result = client.discover_and_call(
    intent="get weather data",
    payload={"city": "London"}
)
print(result)

# Or step by step
service = client.discover("get weather data")
result = client.call_service(service["id"], {"city": "London"})

# Async
result = await client.adiscover_and_call("get weather data", {"city": "London"})

Configuration

Setting Environment Variable Default
API Key AGENTCLEAR_API_KEY (required)
Base URL (constructor arg) https://agentclear.dev
Timeout (constructor arg) 30s

Logging

Enable debug logging to see discovery and call details:

import logging
logging.getLogger("agentclear_fallback").setLevel(logging.DEBUG)

Error Handling

The package raises specific exceptions you can catch:

from agentclear_fallback.core import (
    AgentClearError,            # Base exception
    AuthenticationError,        # Bad or missing API key
    InsufficientBalanceError,   # Account needs more funds
    DiscoveryError,             # No service matched the intent
    ServiceCallError,           # The API call itself failed
)

When your balance is low, the error message includes a direct link to agentclear.dev/billing so you can add funds immediately.


What Services Are Available?

AgentClear's marketplace includes 60+ API services across categories like:

  • Weather โ€” Current conditions, forecasts, historical data
  • Finance โ€” Stock prices, crypto, exchange rates, market data
  • Search โ€” Web search, news, image search
  • AI/ML โ€” Text generation, image recognition, embeddings
  • Documents โ€” PDF conversion, OCR, document parsing
  • Geocoding โ€” Address lookup, reverse geocoding, distance
  • Security โ€” IP reputation, domain scanning, SSL checks
  • Translation โ€” 100+ languages, text and document translation
  • Communication โ€” Email, SMS, push notifications

Browse all services โ†’ agentclear.dev/marketplace


License

MIT โ€” see LICENSE for details.

Project details


Download files

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

Source Distribution

agentclear_fallback-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

agentclear_fallback-0.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file agentclear_fallback-0.1.0.tar.gz.

File metadata

  • Download URL: agentclear_fallback-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for agentclear_fallback-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c0ee87c97f4f1db8a6e67060a3ff70840980c78acbe418a718fcad627d9bef9c
MD5 dfc7ffb47d71b3fa9e0c73784d070c24
BLAKE2b-256 3f6565d55eb6ebd7d1a2fd95f7370e4622f7dfb0bdfce8f7d487565ec9c60b57

See more details on using hashes here.

File details

Details for the file agentclear_fallback-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentclear_fallback-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fa06c347bedc5e736135620c6e2c9f21ce1b6c63ed64b9d80058595e7bb6ef1
MD5 c009ea83d402b421a4174bdeeed0f53b
BLAKE2b-256 c9fcf3e606910ad8216d17ce161c3c044411a1796448308763a8b24fbeb85a32

See more details on using hashes here.

Supported by

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