ToolCallState
🛈 DocStrings¶
Tracks tool call state and sends delta updates.
Instead of accumulating all state and sending everything on each update, this class tracks whether we've started and sends only the fields that are explicitly provided in each update call.
The ACP protocol spec states: "All fields except toolCallId are optional in updates. Only the fields being changed need to be included."
Example flow
- Tool call starts → state.start() sends initial notification
- Progress event → state.update(title="Running...") sends just title
- More progress → state.update(content=[...]) sends just content
- Tool completes → state.complete(raw_output=result) sends status + output
Source code in src/aclientp/tool_call_state.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__init__
¶
__init__(
notifications: ACPNotifications,
tool_call_id: str,
tool_name: str,
title: str,
kind: ToolCallKind,
raw_input: dict[str, Any],
) -> None
Initialize tool call state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notifications
|
ACPNotifications
|
ACPNotifications instance for sending updates |
required |
tool_call_id
|
str
|
Unique identifier for this tool call |
required |
tool_name
|
str
|
Name of the tool being called |
required |
title
|
str
|
Initial human-readable title |
required |
kind
|
ToolCallKind
|
Category of tool (read, edit, execute, etc.) |
required |
raw_input
|
dict[str, Any]
|
Input parameters passed to the tool |
required |
Source code in src/aclientp/tool_call_state.py
complete
async
¶
complete(
raw_output: Any = None,
*,
content: Sequence[ToolCallContent] | None = None,
title: str | None = None,
) -> None
Mark tool call as completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_output
|
Any
|
Final output data |
None
|
content
|
Sequence[ToolCallContent] | None
|
Optional final content |
None
|
title
|
str | None
|
Optional final title |
None
|
Source code in src/aclientp/tool_call_state.py
fail
async
¶
Mark tool call as failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
str | None
|
Error message to display |
None
|
raw_output
|
Any
|
Optional error details |
None
|
Source code in src/aclientp/tool_call_state.py
start
async
¶
Send initial tool_call notification.
This creates the tool call entry in the client UI. Subsequent calls to update() will send tool_call_update notifications with only the changed fields.
Source code in src/aclientp/tool_call_state.py
update
async
¶
update(
*,
title: str | None = None,
status: ToolCallStatus | None = None,
kind: ToolCallKind | None = None,
content: Sequence[ToolCallContent] | None = None,
locations: Sequence[ToolCallLocation | str] | None = None,
raw_output: Any = None,
) -> None
Send an update with only the provided fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Update the human-readable title |
None
|
status
|
ToolCallStatus | None
|
Update execution status |
None
|
kind
|
ToolCallKind | None
|
Update tool kind |
None
|
content
|
Sequence[ToolCallContent] | None
|
Content items (terminals, diffs, text) - replaces previous |
None
|
locations
|
Sequence[ToolCallLocation | str] | None
|
File locations - replaces previous |
None
|
raw_output
|
Any
|
Update raw output data |
None
|
Note
Only fields that are truthy (not None/empty) will be included in the notification. This follows the ACP spec which states that only changed fields need to be sent.