Skip to main content

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 grouping
  • agent_run -- Agent execution
  • step -- Generic step within an agent
  • tool_call -- Tool invocation
  • llm_call -- LLM API call
  • sub_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

Release files for agentscope-otel 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentscope-otel 0.2.1
File Size Uploaded
agentscope_otel-0.2.1.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentscope-otel 0.2.1
File Interpreter ABI Platform
agentscope_otel-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / agentscope_otel-0.2.1.tar.gz

Download URL agentscope_otel-0.2.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
914297bb74cd67ec2c94930310ce63bd6c4a0ef84ef1cc20c7ba3b7107ace763
BLAKE2b-256 checksum
How to use checksums
5658504eae93bf17a4e001d2945a159dbe9672252f0730f5e8d0d5fd232e998e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / agentscope_otel-0.2.1-py3-none-any.whl

Download URL agentscope_otel-0.2.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23c52d6dc84a3e504f691678e6ca7da0875257a5d470084522734489cc9ba696
BLAKE2b-256 checksum
How to use checksums
f824c85fc37083ba8d5014d50f76c0f2ed0d704a7bf5aa36c4939a5130207e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page