Tool calls¶
Tool calls are useful when you want the client to display tool execution as part of the assistant run.
Streaming a tool call¶
Use assistant_stream_ce.create_run.RunController.add_tool_call() to start a tool call and get a
assistant_stream_ce.modules.tool_call.ToolCallController:
import json
async def run(controller):
tool = await controller.add_tool_call("weather")
tool.append_args_text(json.dumps({"location": "Athens"}))
tool.set_response({"temp_c": 18})
The library emits:
tool-call-beginchunkOne or more
tool-call-deltachunks (argument text deltas)A final
tool-resultchunk
Tool call IDs¶
If you don’t provide a tool_call_id, assistant-stream generates one in the call_... style:
Returning artifacts¶
When sending a tool result, you may also include an artifact payload and/or set is_error=True:
tool.set_response(
{"ok": False, "message": "failed"},
artifact={"debug": "..."},
is_error=True,
)
Nested streams¶
Tool calls are implemented as substreams that are merged into the parent stream. You can create more
complex behavior by combining multiple streams with assistant_stream.create_run.RunController.add_stream().