Skip to content

feat: allow mocks to return ToolMessage or Command directly instead of being stringified #64

Open

Description

@Bbenchaya

Problem

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

  1. added
    enhancement
    on Sep 28, 2026
  2. added 2 commits that reference this issue on Nov 23, 2026
    195be9a
    1247a0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions