JsonWrappingToolResponseContentAdapter

Wraps non-JSON tool response content in a JSON object for providers that require valid JSON in tool responses (e.g., Google GenAI / Gemini).

Behavior:

  • Content that is already a JSON object ({...}) or array ([...]) is passed through unchanged.

  • All other content is wrapped as {"result": "<content>"}, including text that merely starts with a bracket, such as [Done] 3 files written.

This acts as a safety net at the provider boundary. Tools are encouraged to return structured JSON directly (see enabledToolsJson() in com.embabel.agent.api.tool.progressive.UnfoldingTool), but this adapter catches any remaining plain-text responses from arbitrary com.embabel.agent.api.tool.Tool implementations.

Content starting with { or [ is parsed before it is passed through: the provider parses it too, and text it cannot parse fails the whole request.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun adapt(content: String): String

Adapt tool response content for the target LLM provider.