AnthropicMessagesToolResponseAdapter is the default ToolResponseAdapter used whenever you pair an agent with the Anthropic Messages adapter. It converts tool outputs into Anthropic tool_result blocks and provides a plain-text fallback that hosts can display or log.
Behavior summary
- Plain-text rendering:
to_plain_textgenerates concise strings for common response types (LinkChunk,JsonChunk,TextChunk,FileChunk,EmptyChunk). - Chat context updates:
create_messagesreturns a user message containing atool_resultblock so the model can consume tool output on the next turn. - Attachment handling: Images and PDFs are converted into Anthropic
imageordocumentblocks; unsupported image types fall back to text. - Developer logging: Emits events via
room.developer.log_nowaitto aid debugging when tools are called.
Response handling
Tool use requirements
Anthropic requires tool results to include atool_use_id. The adapter raises an error if the tool_use block is missing an id.
Extending or replacing
You can subclassAnthropicMessagesToolResponseAdapter to customize plain-text formatting or message content, provided the emitted messages still follow Anthropic’s tool_result schema. Alternatively, supply your own adapter instance when constructing the agent.
Where it is used
- Automatically when you construct
AnthropicMessagesAdapterwithout specifying a customtool_adapter. - Any agent that wants to reuse the same Anthropic formatting logic can import and instantiate it directly.
Related references
- Adapters Overview: Understand LLMAdapters and ToolResponseAdapters
- Anthropic Messages Adapter: Understand the LLM integration that uses this adapter.