Installation
Quick Start
Coding Agent Prompt (Cursor, Claude Code)
Coding Agent Prompt (Cursor, Claude Code)
Copy this prompt into your coding agent (tested with Cursor and Claude Code using Sonnet 4.5):
Basic Configuration
Tracing
Custom (Recommended)
Using get_function() to Link Spans
Declare the trace function key once and link multiple spans together:
Using @simforge.span() Directly
For a single span without linking to a function group:
Automatic Nesting
Spans nest automatically based on call stack:Span Options
Parameters:trace_function_key(required): String identifier for grouping spansname(optional): Display name. Defaults to function name, then trace function keytype(optional): Span type. Defaults to"custom"metadata(optional): Dictionary (dict[str, Any]) attached to the span for custom context (e.g. user ID, region, request ID)
Runtime Metadata
Useget_current_span() to get a handle to the active span, then call .set_metadata() to attach metadata from inside a traced function — useful when metadata depends on runtime values like request IDs, computed scores, or dynamic context:
Error Handling
Errors are captured in the span and re-raised:Flushing Traces
atexit hook.
OpenAI Agents SDK
Attach a trace processor to capture agent runs:Replay
Replay historical traces through a function and create a test run with comparison data. This is useful for testing changes to your functions against real production inputs.fn(required): The function to replay (must be decorated with@span)limit(optional): Maximum number of traces to replay. Default:5trace_ids(optional): List of trace IDs to filter which traces are replayed
- The function must be decorated with
@span— the trace function key is read from the decorator - The function can be sync or async (async functions are detected and run automatically)
- If the function raises an error for one input, replay continues with the remaining inputs
- Each replay creates a test run visible in the Simforge dashboard
- Works through nested decorators (e.g.
@retry,@cache) — walks the__wrapped__chain to find@span
Native Functions
Simforge’s native functions improve prompt tuning efficacy. The auto-tuning engine has full access to prompts—unlike other Agent SDKs that nest user instructions inside system prompts, making prompts inaccessible to tracing.Advanced Configuration
env_vars: Pass LLM provider API keys for local execution (e.g.,{"OPENAI_API_KEY": "..."})execute_locally: WhenTrue(default), fetches prompts from Simforge and executes locally. WhenFalse, executes on Simforge servers.enabled: WhenFalse, all tracing is disabled. Decorated functions still execute normally but no spans are sent.