Python Package: Setup

Configuration & Authentication

When instantiating the Agent class, you must provide these parameters:

  • agent_id: The ID of the agent you want to interact with
  • api_key: Your API key for authentication
  • base_url: API endpoint (default: http://localhost:6669)
  • stream_callback: Optional callback function for streaming responses

Example:

PYTHON
from agent_client import Agent agent = Agent( agent_id="YOUR_AGENT_ID", api_key="YOUR_API_KEY", base_url="https://api.levangielaboratories.com", stream_callback=None # Optional, can be set later )

All subsequent calls will use these authentication details.

WebSocket Streaming

The Agent class supports real-time streaming through WebSockets. You can provide a callback function in two ways:

  1. During initialization:
PYTHON
def my_callback(message): print(f"Received: {message}") agent = Agent( agent_id="YOUR_AGENT_ID", api_key="YOUR_API_KEY", stream_callback=my_callback )
  1. When starting the streaming:
PYTHON
agent.start_streaming(callback=my_callback)

The callback function receives each message from the WebSocket stream as it arrives.

WebSocket Connection Types

The API provides two types of WebSocket connections:

  1. Session-specific: Connected to a single request session
  2. Persistent: Connected to all agent activity

You can choose which to use when starting streaming:

PYTHON
# Use persistent connection (default) agent.start_streaming(callback=my_callback, use_persistent=True) # Use session-specific connection agent.start_streaming(callback=my_callback, use_persistent=False)

Persistent connections are recommended for monitoring all agent activity.