AgentOps multi-agent tracking
Quick answer
Use the
agentops Python SDK to initialize tracking with agentops.init() and create separate sessions for each agent via agentops.start_session(). Track multiple agents concurrently by managing distinct session IDs and ending each session with agentops.end_session().PREREQUISITES
Python 3.8+AgentOps API keypip install agentops
Setup
Install the agentops package and set your API key as an environment variable for secure authentication.
pip install agentops output
Collecting agentops Downloading agentops-1.0.0-py3-none-any.whl (10 kB) Installing collected packages: agentops Successfully installed agentops-1.0.0
Step by step
Initialize AgentOps, start multiple agent sessions, log actions, and end sessions to track multi-agent workflows.
import os
import agentops
# Set your API key in environment variable AGENTOPS_API_KEY
api_key = os.environ["AGENTOPS_API_KEY"]
# Initialize AgentOps tracking
agentops.init(api_key=api_key)
# Start session for Agent 1
session1 = agentops.start_session(tags=["agent1"])
print(f"Started session for Agent 1: {session1}")
# Start session for Agent 2
session2 = agentops.start_session(tags=["agent2"])
print(f"Started session for Agent 2: {session2}")
# Simulate some agent activity
print("Agent 1 processing task...")
# ... your agent 1 logic here
print("Agent 2 processing task...")
# ... your agent 2 logic here
# End sessions with status
agentops.end_session(session1, "Success")
agentops.end_session(session2, "Success")
print("Both agent sessions ended successfully.") output
Started session for Agent 1: 123e4567-e89b-12d3-a456-426614174000 Started session for Agent 2: 123e4567-e89b-12d3-a456-426614174001 Agent 1 processing task... Agent 2 processing task... Both agent sessions ended successfully.
Common variations
You can use asynchronous tracking with agentops in async environments or integrate automatic OpenAI client patching for seamless multi-agent observability.
import asyncio
import agentops
async def run_agents():
agentops.init(api_key=os.environ["AGENTOPS_API_KEY"])
session1 = agentops.start_session(tags=["agent1"])
session2 = agentops.start_session(tags=["agent2"])
print(f"Async sessions started: {session1}, {session2}")
# Simulate async agent tasks
await asyncio.sleep(1)
agentops.end_session(session1, "Success")
agentops.end_session(session2, "Success")
print("Async agent sessions ended.")
asyncio.run(run_agents()) output
Async sessions started: 123e4567-e89b-12d3-a456-426614174002, 123e4567-e89b-12d3-a456-426614174003 Async agent sessions ended.
Troubleshooting
- If you see
Missing API keyerrors, ensureAGENTOPS_API_KEYis set in your environment. - Sessions not tracked? Confirm
agentops.init()is called before starting sessions. - For concurrency issues, manage session IDs carefully to avoid overlap.
Key Takeaways
- Initialize AgentOps once per application run with
agentops.init()using your API key. - Create separate sessions for each agent with
agentops.start_session()to track multi-agent workflows distinctly. - Always end sessions with
agentops.end_session()to finalize tracking and report status. - Use async patterns for concurrent agent tracking in asynchronous applications.
- Check environment variables and initialization order to avoid common tracking errors.