Skip to content

Conversation

@wingding12
Copy link

Summary

Fixes #1104

When @agent, @tool, and other decorators are used without calling agentops.init() first, they now provide clear feedback instead of silently failing.

Root Cause

The decorator factory checked if not tracer.initialized: and silently returned the function result without any indication that tracing wasn't happening. This caused confusion because:

  • LLM instrumentation (via providers) worked because it has its own initialization
  • Decorators silently passed through without creating spans
  • Users had no way to know their decorators weren't working

Solution

Added _ensure_tracer_initialized() helper that:

  1. Shows a clear warning message explaining the issue
  2. Suggests solutions: call agentops.init() or set AGENTOPS_AUTO_INIT=true
  3. Only shows warning once to avoid log spam
  4. Still executes the decorated function normally (graceful degradation)

New Environment Variable

AGENTOPS_AUTO_INIT=true - When set, decorators will auto-initialize AgentOps with sensible defaults:

  • auto_start_session=False
  • instrument_llm_calls=True

Files Changed

  • agentops/sdk/decorators/factory.py - Add initialization check with warning
  • tests/unit/sdk/test_decorators.py - Add tests for warning behavior

Test Plan

  • Test that warning is shown when tracer not initialized
  • Test that warning is only shown once (no spam)
  • Test that decorated functions still execute without tracer

Fixes AgentOps-AI#1104

When @agent, @tool, and other decorators are used without calling
agentops.init() first, they now:

1. Show a clear warning message explaining the issue
2. Suggest solutions (call agentops.init() or set AGENTOPS_AUTO_INIT=true)
3. Only show the warning once to avoid log spam
4. Still execute the decorated function normally

Added AGENTOPS_AUTO_INIT environment variable option that allows
automatic initialization when decorators are used.

Changes:
- agentops/sdk/decorators/factory.py: Add _ensure_tracer_initialized()
- tests/unit/sdk/test_decorators.py: Add tests for warning behavior
@wingding12 wingding12 marked this pull request as draft January 27, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decorator Initialization Failures: @agent and @tool decorators don't work while LLM instrumentation does

1 participant