tinker_cookbook.tool_use.simple_tool_result
tinker_cookbook.tool_use.simple_tool_result(content, call_id, name, should_stop, metrics, metadata)
Helper function to create a ToolResult from content.
content accepts either a plain string or a list[ContentPart] for
multimodal results (e.g. text interleaved with images). This matches the
Message["content"] type, so callers can build parts in any order.
Parameters:
- content (str | list[ContentPart]) – Content to return to the model — a string or list of ContentPart.
- call_id (str) – The tool call ID (usually passed from ToolInput).
- name (str) – The tool name (usually self.name in a tool method).
- should_stop (bool) – Whether to stop the episode after this tool call.
- metrics (dict[str, float] | None) – Optional metrics dict (e.g., {"latency": 0.5, "count": 1}).
- metadata (dict[str, Any] | None) – Optional metadata dict for debugging.
Returns: A ToolResult with the given content and options.
@tool
async def search(query: str) -> ToolResult:
results = await do_search(query)
return simple_tool_result(
json.dumps(results),
metrics={"result_count": len(results)}
)
@tool
async def screenshot() -> ToolResult:
img = take_screenshot()
return simple_tool_result(
[TextPart(type="text", text="Screenshot taken"),
ImagePart(type="image", image=img)],
)