Pattern: @reflect_trace Decorator
The decorator pattern is the lowest-friction way to add Reflect to an existing agent function. Annotate your function with @reflect_trace and Reflect handles memory retrieval, trace submission, and retrieved_memory_ids tracking - you just write the agent logic.
WebSearchTool.
Prerequisites
Full example
openai_agents_reflect_simple.py
Run it
How it works
Annotate your function with @reflect_trace
The decorator intercepts the call, retrieves relevant memories, and injects a
TraceContext as the first argument. The task parameter tells Reflect how to extract the task string from your function’s arguments.ctx.augmented_task contains the original question with past memories appended. Pass this to the agent instead of the raw question.Run the agent with augmented context
The agent receives the memory-augmented prompt, so it can draw on what worked (or didn’t) in previous runs.
Convert the agent result to a trajectory
from_openai_agents converts the agent’s message history into the format Reflect expects.Adding a review
To close the learning loop immediately, includeresult in TraceResult:
result, the trace is stored with a pending review status and can be reviewed later from the dashboard.