Skip to content

Add LLMExclude field annotation for agent tool results#210

Merged
alex-w-99 merged 2 commits intomainfrom
agent-tool-decorator
Feb 27, 2026
Merged

Add LLMExclude field annotation for agent tool results#210
alex-w-99 merged 2 commits intomainfrom
agent-tool-decorator

Conversation

@alex-w-99
Copy link
Contributor

@alex-w-99 alex-w-99 commented Feb 27, 2026

Updates include:

  • Adds LLMExclude marker for Pydantic fields that should be stripped before tool results reach the LLM. Use via Annotated[str, LLMExclude()].
  • Stripping is automatic in _execute_tool(). Tool handlers can return models directly instead of manually cherry-picking fields into dicts.
  • Handles nested models, lists, tuples, dicts recursively; preserves @computed_field properties.
  • Moved serialize_tool_result to new bluebox/utils/llm_serialization.py module (now returns SerializedToolResult named tuple).
  • 68 unit tests + 6 integration tests covering stripping, serialization, and the _execute_tool hook.

…t tool results

Add LLMExclude marker class (used via Annotated[Type, LLMExclude()]) that lets
Pydantic model fields be automatically stripped before tool results reach the LLM.
This replaces manual dict cherry-picking in tool handlers.

- New module: bluebox/utils/llm_serialization.py
  - LLMExclude marker, strip_llm_excluded() recursive stripper
  - serialize_tool_result() moved here from abstract_agent.py (now SerializedToolResult NamedTuple)
  - Cached _excluded_fields() per model class
  - Handles computed_field properties correctly
- Hook in AbstractAgent._execute_tool() applies stripping automatically
- Comprehensive tests: 68 unit tests + 6 integration tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@alex-w-99 alex-w-99 changed the base branch from main to messing-around February 27, 2026 20:53
@alex-w-99 alex-w-99 changed the base branch from messing-around to main February 27, 2026 20:53
@alex-w-99 alex-w-99 marked this pull request as ready for review February 27, 2026 21:58
@alex-w-99 alex-w-99 merged commit 2351cd0 into main Feb 27, 2026
8 checks passed
@alex-w-99 alex-w-99 deleted the agent-tool-decorator branch February 27, 2026 22:03
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.

2 participants