Tool runtime: state, context, store, stream writer
Notebook· 02.04· 120–150 min· Lesson 22 of 129
The notebook opens in your lab, in a new tab. If your server is stopped, it starts first (a few seconds).
By the end you can
- Inject runtime data into tools with
ToolRuntime, so the model never sees (or controls) it. - Pass typed per-request data with
context_schema+invoke(..., context=...). - Read agent state in a tool and write to it by returning a
Command. - Use a
storefor data that outlives a run, andstream_writerfor progress events. - Handle the three kinds of tool failure, and know which ones crash the agent by default.
- Apply
ToolErrorMiddleware,wrap_tool_callandToolCallLimitMiddleware, with safe error messages.
Before you start
Lesson 02.03 (create_agent).
Python in this lesson
Python guideNew hereoperator
