Python Package: Functions
Overview
Below are the core functionalities you'll use when working with our Python client library. You can interact with your agents in two main ways:
- Using the
Agent
class – for easy messaging, file uploads, and streaming. - Using legacy standalone functions – if you prefer a more functional style.
Examples with the `Agent` Class
PYTHONfrom agent_client import Agent API_KEY = "YOUR_API_KEY" AGENT_ID = "YOUR_AGENT_ID" # Create an Agent instance agent = Agent( agent_id=AGENT_ID, api_key=API_KEY, base_url="https://api.levangie-laboratories.com" ) # Send a message response = agent.message("Hello, Agent!") print("Response:", response) # Upload a file with open("my_local_file.txt", "rb") as f: upload_resp = agent.upload_file("agent_data/file.txt", f) print("Upload response:", upload_resp) # Stream responses (requires async websockets in the background) # Provide a callback that handles each chunk of streamed data def handle_streamed_data(data): print("Stream received:", data) agent.start_streaming(callback=handle_streamed_data) # Do something else... # When finished, stop streaming: agent.stop_streaming()
Examples with Legacy Functions
PYTHONfrom agent_client import send_operation, upload_file API_KEY = "YOUR_API_KEY" AGENT_ID = "YOUR_AGENT_ID" BASE_URL = "https://api.levangie-laboratories.com" # Send an operation (e.g., message) resp = send_operation( operation="message", params={"text": "Hello via operation!"}, api_key=API_KEY, agent_id=AGENT_ID, base_url=BASE_URL ) print("Operation response:", resp) # Upload a file with open("./localfile.txt", "rb") as f: up_resp = upload_file( api_key=API_KEY, agent_id=AGENT_ID, file_path="/agent_data/uploaded.txt", file_to_upload=f, base_url=BASE_URL ) print("Upload file response:", up_resp)
Additional Account Functions
The package also supports account and usage queries:
client.get_credits()
: Check total remaining creditsclient.get_agents()
: List all your agentsclient.get_total_stats()
: View total usage statsclient.get_agent_stats(agent_id)
: View usage for a specific agent
These calls can help you monitor and control costs.