Instrument
Add observability to your AI agents with automatic and manual instrumentation.
The Instrument section covers everything you need to add observability to your AI agents.
Overview
Risicare provides multiple ways to instrument your code:
- Auto-Instrumentation - Zero-code tracing of LLM providers
- SDK Decorators - Rich context with
@agent,@trace_*decorators - Framework Integrations - Native support for LangGraph, CrewAI, AutoGen
Choose Your Approach
SDK Reference
Core SDK configuration and decorators
LLM Providers
OpenAI, Anthropic, Cohere, and more
Frameworks
LangGraph, CrewAI, AutoGen integrations
Progressive Integration
Start simple and add depth as needed:
Tier 0: One Import
Add import risicare to your entrypoint and set RISICARE_API_KEY and
RISICARE_TRACING=true for automatic instrumentation of the LLM calls of supported providers. The environment variables are read
when the SDK is imported — a process that never imports risicare emits no spans.
export RISICARE_API_KEY=rsk-your-api-key
export RISICARE_TRACING=trueimport risicare # the one line you add
# ... your agent code, unchanged ...Tier 1: Explicit Init
Call risicare.init() for configuration control.
import risicare
risicare.init(environment="production")Tier 2: Agent Identity
Use @agent() to identify agent functions.
from risicare import agent
@agent(name="planner", role="orchestrator")
def plan(objective):
passTier 3: Sessions
Group traces with @session or session_context().
from risicare import session_context
with session_context(session_id=user_session):
agent.run(query)Tier 4: Phases
Track decision phases with @trace_think, @trace_decide, @trace_act.
from risicare import trace_think, trace_decide, trace_act
@trace_think
def analyze(): pass
@trace_decide
def choose(): pass
@trace_act
def execute(): passTier 5: Multi-Agent
Track messages with @trace_message, @trace_delegate.
from risicare import trace_message, trace_delegate
@trace_message
def send_to_reviewer(msg): pass
@trace_delegate
def assign_subtask(task): passWhat Gets Captured
| Data | Auto | With Decorators |
|---|---|---|
| LLM calls (provider, model, parameters) | ✓ | ✓ |
| Prompt and completion text | Off by default | Off by default |
| Token counts & costs | ✓ | ✓ |
| Latency & timing | ✓ | ✓ |
| Agent identity | - | ✓ |
| Session grouping | - | ✓ |
| Decision phases | - | ✓ |
| Inter-agent messages | - | ✓ |
| Custom attributes | - | ✓ |
Prompt and completion text is recorded only when two switches are on: trace_content=True
in the SDK (off by default), and the project's content setting. In the JavaScript
SDK, patchOpenAI and patchAnthropic record the text; a streamed call records the prompt
only. The other JavaScript providers record no text.
The text of an error is not covered by these switches. The exception message, the stack
trace, the span status message and the error.message attribute are exported also when
content capture is off. If a provider's error message repeats part of a prompt, that text
is in those fields. To filter them in Python, use mask: it receives statusMessage,
exceptions.{i}.message, exceptions.{i}.stacktrace and error.message.