Skip to content

fix(reasoning): attach tool calls to their step in get_trace_with_steps - #142

Open
Andy2003 wants to merge 1 commit into
neo4j-labs:mainfrom
Andy2003:fix/reasoning-tool-calls-readback
Open

fix(reasoning): attach tool calls to their step in get_trace_with_steps#142
Andy2003 wants to merge 1 commit into
neo4j-labs:mainfrom
Andy2003:fix/reasoning-tool-calls-readback

Conversation

@Andy2003

Copy link
Copy Markdown
Collaborator

Problem

ReasoningMemory.get_trace_with_steps() always returns step.tool_calls == [], even when tool calls were recorded. The data is stored correctly — the reader just can't see it.

Root cause: record_tool_call() links a ToolCall to its ReasoningStep via the (:ReasoningStep)-[:USES_TOOL]->(:ToolCall) relationship, but never sets a step_id property on the node. GET_TRACE_WITH_STEPS flat-collected the tool-call nodes and the parser grouped them by tc.get("step_id") — which is always None — so no tool call ever attached to a step.

This surfaced while wiring record_tool_calls=True on the Strands Neo4jSessionManager: the ToolCall nodes were present in Neo4j (correct USES_TOOL edges), but the high-level reader reported none.

Fix

Derive the step↔tool-call association from the relationship instead of an absent property:

  • GET_TRACE_WITH_STEPS now emits {step_id: rs.id, tool_call: tc} pairs.
  • get_trace_with_steps() parses that shape and also populates ToolCall.step_id on the returned objects.

Relationship-sourced, so it works for already-stored data — no migration required. No change to the write path.

Test

Adds test_get_trace_with_steps_includes_tool_calls (integration). Verified red→green: fails (assert 0 == 1) before the fix, passes after. Full tests/integration/test_reasoning_memory.py suite (30 tests) and tests/unit/nams/test_reasoning.py (22 tests) pass.

🤖 Generated with Claude Code

`record_tool_call` links a ToolCall to its ReasoningStep via the
`USES_TOOL` relationship but never sets a `step_id` property on the node.
`get_trace_with_steps` grouped tool calls by that absent property, so
`step.tool_calls` always came back empty even though the data was stored
correctly.

Derive the step association from the relationship in `GET_TRACE_WITH_STEPS`
(emitting `{step_id, tool_call}` pairs) and update the parser accordingly.
Works for already-stored data — no migration needed — and now also
populates `ToolCall.step_id` on the returned objects.

Adds a regression integration test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

@Andy2003 is attempting to deploy a commit to the lyonwj's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant