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 withapi_key
: Your API key for authenticationbase_url
: API endpoint (default: http://localhost:6669)stream_callback
: Optional callback function for streaming responses
Example:
PYTHONfrom 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:
- During initialization:
PYTHONdef my_callback(message): print(f"Received: {message}") agent = Agent( agent_id="YOUR_AGENT_ID", api_key="YOUR_API_KEY", stream_callback=my_callback )
- When starting the streaming:
PYTHONagent.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:
- Session-specific: Connected to a single request session
- 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.