You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: allow mocks to return ToolMessage or Command directly instead of being stringified #64
The real-tool path in create_mockable_tool_wrapper returns whatever execute(request) returns — ToolMessage | Command. The mock path does not: _format_mock_result accepts str | dict | list and str()s anything else, then wraps it in a ToolMessage(status="success").
So a mock cannot faithfully stand in for tools that:
return a Command to update graph state (InjectedToolCallId + Command(update={...}) pattern from the LangGraph docs)
use response_format="content_and_artifact" and rely on ToolMessage.artifact
need status="error" without raising (e.g. to exercise the agent's error-message handling deterministically)
Returning a ToolMessage from a mock today yields a ToolMessage whose content is the repr() of another ToolMessage.
Proposed behaviour
In the mock branch of the wrapper, before _format_mock_result:
if the result is a Command → return it as-is (record result=command)
if the result is a ToolMessage → fill in name / tool_call_id when missing, return it (respect its status)
if the result is a (content, artifact) tuple and the real tool declares content_and_artifact → build the ToolMessage with artifact
otherwise → current behaviour
Also let data-driven cases express status/artifact declaratively, e.g. {"output": {...}, "status": "error"} — can be a follow-up.
Files
src/stuntdouble/wrapper.py
tests/test_wrapper.py
docs/guides/langgraph-integration.md
Filed with AI assistance (Cursor) during a maintainer issue audit.
Activity
feat: let mocks return ToolMessage or Command directly
feat: fill in tool_call_id on ToolMessages inside a mocked Command