Skip to main content

Python SDK Reference

The agentvisor Python SDK provides utilities for agents running inside AgentVisor™.

Availability

The AgentVisor SDK is automatically available in containerized execution. You can immediately use:

from agentvisor import checkpoint, store

Structured logging works out of the box with standard logging.getLogger(__name__) — no agentvisor import required. See Agent Logging for details, including the optional agentvisor.logging.get_logger() convenience wrapper.

For local development with --sandbox=none, see SDK Installation.

Overview

The SDK provides essential features for production agents including checkpointing, structured logging, key-value storage, and MCP integration:

ModulePurpose
langgraphLangGraph integration (checkpointer, graph discovery)
checkpointDirect checkpoint API
streamEmit stream chunks
storeLong-term memory
statePer-thread key-value state
mcpMCP client integration
a2aA2A agent communication
schema@agent, @tool decorators
loggingStructured logging
langchainLangChain integration (MCP/A2A tools)
configEnvironment-based configuration
retryAutomatic retry with exponential backoff

Basic Usage

LangGraph Checkpointer

from agentvisor.langgraph import AgentVisorCheckpointer
from langgraph.graph import StateGraph

builder = StateGraph(MyState)
# ... build graph ...

graph = builder.compile(checkpointer=AgentVisorCheckpointer())

Environment Variables

The SDK reads configuration from environment variables set by AgentVisor:

VariableDescription
AGENTVISOR_AGENT_SOCKETPath to agent Unix socket
AGENTVISOR_THREAD_IDCurrent thread ID
AGENTVISOR_RUN_IDCurrent run ID
HTTP_PROXYProxy URL for HTTP requests

These are set automatically - you don't need to configure them.

Automatic Retry

The SDK automatically retries operations that encounter transient failures (network blips, rate limiting, timeouts). This happens transparently - your agent code doesn't need to handle these cases.

Transient errors that trigger retry:

  • UNAVAILABLE - Service temporarily down
  • DEADLINE_EXCEEDED - Request timeout
  • RESOURCE_EXHAUSTED - Rate limiting

Retries use exponential backoff with jitter to prevent thundering herd problems.

# This automatically retries on transient failures
checkpoint.save("my-state", data)

# Configure retry behavior if needed
from agentvisor.retry import configure_retry, RetryConfig

configure_retry(checkpoint=RetryConfig(max_attempts=5, base_delay_ms=200))

See the Retry Mechanisms reference for configuration options and details.

Error Handling

SDK functions raise specific exceptions:

from agentvisor.client import StoreNotEnabledError

# Store operations raise StoreNotEnabledError if store not configured
try:
from agentvisor import store
store.put("ns", "key", {"value": 1})
except StoreNotEnabledError:
print("Store API is not enabled on the host")
note

Transient gRPC errors (UNAVAILABLE, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED) are automatically retried before being raised. Exceptions you catch have already exhausted their retry budget.