Json Wrapping Tool Response Content Adapter
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 already looks like a JSON object (
{...}) or array ([...]) is passed through unchanged.All other content is wrapped as
{"result": "<content>"}.
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.
Note: The startsWith check is a fast-path heuristic, not full JSON validation. Malformed JSON-like strings (e.g., {not json}) will pass through and may fail downstream — this is acceptable since such output is extremely rare from well-behaved tools.