Skip to content

fix(crew): don't report a successful tool call as failed when its result isn't JSON-native - #158

Open
Shraman123 wants to merge 1 commit into
smallest-inc:mainfrom
Shraman123:crew-tool-result-serialization
Open

Shraman123 wants to merge 1 commit into
smallest-inc:mainfrom
Shraman123:crew-tool-result-serialization

Conversation

@Shraman123

Copy link
Copy Markdown

Problem

ToolRegistry._execute_single serializes dict/list tool results with a bare json.dumps(result). If the result contains a datetime, Decimal, UUID, … that call raises after the tool has already run, and the except branch turns a successful call into a failure:

  • tool_call_error is emitted instead of tool_call_end
  • the LLM receives is_error=True with "Object of type datetime is not JSON serializable"

For a tool with side effects (booking, payment, CRM write) that invites the model to call it again and repeat the side effect.

Repro on main:

import asyncio, datetime
from smallestai.atoms.crew.tools import function_tool
from smallestai.atoms.crew.tools.registry import ToolRegistry
from smallestai.atoms.crew.clients.types import ToolCall

booked = []

@function_tool
def book_slot(day: str):
    """Book a slot."""
    booked.append(day)
    return {"booked": True, "at": datetime.datetime(2026, 9, 29, 10, 0)}

r = ToolRegistry(); r.register(book_slot)
[res] = asyncio.run(r.execute([ToolCall(id="1", name="book_slot", arguments='{"day": "mon"}')]))
print(res.is_error, res.content, booked)
# True  Object of type datetime is not JSON serializable  ['mon']   <- booked, but reported as failed

Fix

json.dumps(result, default=str). Non-JSON-native values come through as their string form. Results that are already plain JSON serialize byte-identically. One-line change in src/smallestai/atoms/crew/tools/registry.py (.fernignored).

Tests

New tests/custom/test_tool_registry_result_serialization.py:

  • datetime/Decimal/UUID result → is_error=False, correct content, events tool_call_start → tool_call_end (fails on main)
  • plain JSON result → content unchanged

pytest tests/custom: 280 passed; the only 2 failures (test_region_aware_auth) fail identically on main locally and are unrelated. ruff check clean on the changed files.

🤖 Generated with Claude Code

…ult isn't JSON-native

ToolRegistry._execute_single serialized dict/list results with a bare
json.dumps, so a tool returning e.g. {"at": datetime(...)} raised after
the tool had already run. The except branch then emitted tool_call_error
and returned is_error=True ("Object of type datetime is not JSON
serializable") to the LLM, which for a booking/payment tool invites a
retry that repeats the side effect.

Serialize with default=str so datetime / Decimal / UUID etc. come through
as strings. Plain JSON results are byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@crim-app

crim-app Bot commented Nov 15, 2026

Copy link
Copy Markdown

crim doesn't review pull requests automatically here.

Comment crim review on this pull request whenever you want a review.

This branch has not been deployed

No deployments
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