Skip to main content

AgentWorks SDK - Instrument and observe multi-agent AI systems

Project description

AgentWorks Python SDK

Instrument and observe your multi-agent AI systems with a single line of code.

Installation

pip install agentworks

Quick Start

from agentworks import trace_agent, trace_tool, llm_call, configure

# Configure SDK
configure(
    ingest_endpoint="http://localhost:8080",
    org_id="my-org",
    project_id="my-project",
)

# Trace your agent
with trace_agent("support-bot", workflow_id="ticket-123"):
    
    # Trace tool calls
    with trace_tool("fetch_user_data"):
        user = fetch_user_data(user_id)
    
    # Trace LLM calls with automatic cost tracking
    result = llm_call(
        model="gpt-4",
        provider="openai",
        prompt=f"Summarize: {user.history}",
        completion=response_text,
        prompt_tokens=150,
        completion_tokens=50,
    )

Features

  • Zero-overhead instrumentation: <5ms latency per span
  • Automatic cost tracking: Built-in pricing for OpenAI, Anthropic, Google
  • PII detection & redaction: Protect sensitive data automatically
  • W3C trace propagation: Compatible with OpenTelemetry
  • Framework agnostic: Works with any Python agent framework

API Reference

Configuration

configure(
    ingest_endpoint="http://localhost:8080",  # AgentWorks API endpoint
    api_key="aw_...",                         # API key (optional for dev)
    org_id="my-org",                          # Organization ID
    project_id="my-project",                  # Project ID
    redact_pii=True,                          # Enable PII redaction
    debug=False,                              # Enable debug logging
)

Tracing

trace_agent(agent_id, workflow_id=None, **attrs)

Trace an agent execution.

with trace_agent("support-bot", workflow_id="ticket-123") as span_id:
    # Agent logic here
    pass

trace_tool(name, **attrs)

Trace a tool execution.

with trace_tool("stripe_refund", amount="50.00") as span_id:
    # Tool logic here
    pass

trace_decision(policy="default", **attrs)

Trace a decision point.

with trace_decision(policy="routing-v1", task="classification") as span_id:
    model = select_model(task)

llm_call(model, provider, prompt, completion, prompt_tokens, completion_tokens, **attrs)

Trace an LLM call with automatic cost calculation and PII detection.

result = llm_call(
    model="gpt-4",
    provider="openai",
    prompt="Classify: ...",
    completion="Category: Support",
    prompt_tokens=100,
    completion_tokens=10,
    temperature=0.7,
)
# Returns: {"trace_id": "...", "span_id": "...", "cost_usd": 0.0045, "pii_detected": []}

Utilities

get_current_trace_id()

Get the current trace ID.

trace_id = get_current_trace_id()

get_current_span_id()

Get the current span ID.

span_id = get_current_span_id()

Supported Models

The SDK includes built-in pricing for:

  • OpenAI: GPT-4, GPT-4 Turbo, GPT-4o, GPT-3.5 Turbo
  • Anthropic: Claude 3 Opus, Sonnet, Haiku, Claude 3.5 Sonnet
  • Google: Gemini Pro, Gemini 1.5 Pro/Flash

PII Detection

Automatically detects and redacts:

  • Email addresses
  • Phone numbers
  • Social Security Numbers
  • Credit card numbers
  • API keys

Configure PII patterns:

configure(
    redact_pii=True,
    pii_patterns="email,phone,ssn,credit_card,api_key",
)

Examples

See examples/agents-python/ for complete examples:

  • support_flow.py - Customer support agent with error handling and PII
  • research_flow.py - Research agent with multiple tools
  • extractor_flow.py - Data extraction agent

Development

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Run linter
poetry run ruff check agentworks

# Type check
poetry run mypy agentworks

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentworks-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentworks-0.1.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file agentworks-0.1.1.tar.gz.

File metadata

  • Download URL: agentworks-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.2 Darwin/25.0.0

File hashes

Hashes for agentworks-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77d77de7f4e199377bfacb438b7e17c02cff62ad4d20b0ac84ca2a73f6af0851
MD5 0a99997a924b24fa1ddb964ec57f2038
BLAKE2b-256 cb47fd8ebce6b39516fdbf9200caba84a7d9f3445b7281c800a73bbe8df15ca9

See more details on using hashes here.

File details

Details for the file agentworks-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: agentworks-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.2 Darwin/25.0.0

File hashes

Hashes for agentworks-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d54a310435db4c030521ca1fd929415b4af8ca12719bc2e4edce73a5461f7fd
MD5 6282469f5ac636996374e3fb9a79b57c
BLAKE2b-256 2ffcb02992d6289733e2dbcea475141c492d53c486f473d4793dc1c4fa09d301

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page