cognee.agent_memory(save_session_traces=True), call it a couple of times, then recall what happened — including calls that raised an error.
Before You Start
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured — the initial
remember()call needs one, even though tracing itself does not - Read Sessions first — this guide assumes you already know what
session_idis and how it works
Code in Action
What Just Happened
Step 1: Bootstrap Cognee and Decorate the Function
remember() call runs once, before anything else, purely to make sure Cognee’s database and default user exist — the decorated function itself never reads this fact back, because with_memory=False. save_session_traces=True is what turns tracing on — without it, the decorator would still run the function but record nothing. with_memory=False and with_session_memory=False keep this example focused on traces alone: no graph memory lookup, no conversation-history retrieval, just “what happened when this function ran.” session_trace_summary=False skips the LLM-generated summary Cognee would otherwise attempt for each trace.
Step 2: Call It Once Successfully
"Alice" is in statuses, so the function returns normally. Behind the scenes, the decorator records this call’s trace with status="success" and the returned value — automatically, without you constructing any trace object yourself.
Step 3: Call It Again With an Error
"Bob" is not in statuses, so the function raises ValueError. The decorator still records this call’s trace — this time with status="error" and the error message — then re-raises the exception, which is why the call is wrapped in try/except here.
Step 4: Recall the Traces
scope="trace" tells recall() to search recorded traces instead of the knowledge graph or conversation history. Trace search matches by keyword across each trace’s function name, parameters, return value, and error message — query_text="Alice" matches the first call because "Alice" appears in its parameters. Each result exposes origin_function, status, method_params, method_return_value, and error_message, so both the successful call and the failed one are fully inspectable.
Step 5: Confirm Isolation Between Sessions
session_id that never ran lookup_teammate_status returns an empty list — traces are scoped per session, just like the conversation history covered in Sessions.
Traces vs. Other Session Concepts
Traces vs. conversation history
Traces vs. conversation history
A trace records one function call — its inputs, status, and outcome. Conversation history (covered in Sessions) records question/answer turns from
recall(). Both live in the same session cache and are scoped by session_id, but they answer different questions: “what did this code do?” vs. “what did we discuss?”Traces vs. memory_context and automatic guidance
Traces vs. memory_context and automatic guidance
This guide keeps
with_memory=False and with_session_memory=False so the decorated function never reads graph memory or session history back — it only writes traces. Enabling those flags (as examples/guides/agent_memory_quickstart.py does) lets a decorated function use memory during its own execution, which is a separate, more advanced concept from recording that the call happened.Traces vs. graph persistence
Traces vs. graph persistence
Traces recorded here stay in the session cache — they are not written to the permanent knowledge graph. Bridging session content (including traces) into the graph is handled by
improve(session_ids=...), the same mechanism covered in Session Distillation, and is out of scope for this guide.Sessions
Learn the session-cache concept traces are built on
Agent Memory Quickstart
See traces combined with session memory and graph memory