Python SDK for AgentScope — AI Agent Observability with OpenTelemetry
Project description
agentscope-otel
Python SDK for AgentScope -- AI Agent Observability.
Installation
pip install agentscope-otel
Quick Start
from agentscope_otel import AgentScope
# Initialize once at startup (3 lines!)
scope = AgentScope.init(
endpoint="http://localhost:3001",
project_id="my-project",
)
# Use decorators for automatic span management
@scope.wrap_agent("my-agent", agent_name="researcher", agent_task="Answer questions")
async def run_agent(question: str):
# Nested tool call -- auto-linked via context propagation
with scope.trace_tool("web-search") as span:
results = await search(question)
# LLM call with auto token tracking
@scope.wrap_llm_call("generate", model="claude-sonnet-4-5")
async def call_llm(prompt):
return await llm.complete(prompt) # should have input_tokens, output_tokens attrs
return await call_llm(f"Summarize: {results}")
# Run and clean up
import asyncio
asyncio.run(run_agent("What is AgentScope?"))
scope.flush()
API
Initialization
scope = AgentScope.init(
endpoint="http://localhost:3001",
project_id="my-project",
tenant_id="default", # optional
api_key="sk-...", # optional
service_name="my-service", # optional
debug=True, # optional
)
Decorators
@scope.wrap_agent("name", agent_name="...", agent_task="...")
@scope.wrap_tool("name", agent_name="...")
@scope.wrap_step("name")
@scope.wrap_llm_call("name", model="claude-sonnet-4-5")
Context Managers
with scope.trace_agent("name") as span:
...
with scope.trace_tool("name") as span:
...
with scope.trace_step("name") as span:
...
Manual Span Control
span = scope.create_agent_span("name", agent_name="...")
# ... work ...
span.end()
llm_span = scope.create_llm_span("name", model="claude-sonnet-4-5")
# ... call LLM ...
scope.end_llm_span(llm_span, LLMResult(input_tokens=100, output_tokens=50))
Cost Calculation
from agentscope_otel import calculate_cost, MODEL_PRICING
cost = calculate_cost("claude-sonnet-4-5", input_tokens=1000, output_tokens=500)
Supported Models
| Model | Input (cents/1M tokens) | Output (cents/1M tokens) |
|---|---|---|
| gpt-4o | 250 | 1000 |
| gpt-4o-mini | 15 | 60 |
| claude-sonnet-4-5 | 300 | 1500 |
| claude-haiku-4-5 | 80 | 400 |
| claude-opus-4-6 | 1500 | 7500 |
| gemini-2.0-flash | 10 | 40 |
Span Types
session-- Top-level session groupingagent_run-- Agent executionstep-- Generic step within an agenttool_call-- Tool invocationllm_call-- LLM API callsub_agent-- Nested agent invocation
Example
A runnable quickstart is included in examples/quickstart.py:
python examples/quickstart.py
Requirements
- Python 3.10+
- OpenTelemetry Python SDK
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
agentscope_otel-0.2.1.tar.gz
(10.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentscope_otel-0.2.1.tar.gz.
File metadata
- Download URL: agentscope_otel-0.2.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
914297bb74cd67ec2c94930310ce63bd6c4a0ef84ef1cc20c7ba3b7107ace763
|
|
| MD5 |
a78871a7a178111d45fd89a40e5869ad
|
|
| BLAKE2b-256 |
5658504eae93bf17a4e001d2945a159dbe9672252f0730f5e8d0d5fd232e998e
|
File details
Details for the file agentscope_otel-0.2.1-py3-none-any.whl.
File metadata
- Download URL: agentscope_otel-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23c52d6dc84a3e504f691678e6ca7da0875257a5d470084522734489cc9ba696
|
|
| MD5 |
f3a458ccdadb0acc97b1c1753409cef7
|
|
| BLAKE2b-256 |
f824c85fc37083ba8d5014d50f76c0f2ed0d704a7bf5aa36c4939a5130207e11
|