mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
Fix empty tool-use response handling
This commit is contained in:
24
README.md
24
README.md
@@ -115,7 +115,7 @@ The takeaway is not "copy Claude Code." The takeaway is: **the best agent produc
|
||||
|
||||
User --> messages[] --> LLM --> response
|
||||
|
|
||||
stop_reason == "tool_use"?
|
||||
contains tool_use block?
|
||||
/ \
|
||||
yes no
|
||||
| |
|
||||
@@ -142,18 +142,20 @@ def agent_loop(messages):
|
||||
messages.append({"role": "assistant",
|
||||
"content": response.content})
|
||||
|
||||
if response.stop_reason != "tool_use":
|
||||
tool_calls = [
|
||||
block for block in response.content if block.type == "tool_use"
|
||||
]
|
||||
if not tool_calls:
|
||||
return
|
||||
|
||||
results = []
|
||||
for block in response.content:
|
||||
if block.type == "tool_use":
|
||||
output = TOOL_HANDLERS[block.name](**block.input)
|
||||
results.append({
|
||||
"type": "tool_result",
|
||||
"tool_use_id": block.id,
|
||||
"content": output,
|
||||
})
|
||||
for block in tool_calls:
|
||||
output = TOOL_HANDLERS[block.name](**block.input)
|
||||
results.append({
|
||||
"type": "tool_result",
|
||||
"tool_use_id": block.id,
|
||||
"content": output,
|
||||
})
|
||||
messages.append({"role": "user", "content": results})
|
||||
```
|
||||
|
||||
@@ -300,7 +302,7 @@ flowchart TD
|
||||
|
||||
| Chapter | Topic | Key Concepts |
|
||||
|---|---|---|
|
||||
| [s01](./s01_agent_loop/) | Agent Loop | `messages` / `while True` / `stop_reason` |
|
||||
| [s01](./s01_agent_loop/) | Agent Loop | `messages` / `while True` / `tool_use` |
|
||||
| [s02](./s02_tool_use/) | Tool Use | `TOOL_HANDLERS` / dispatch map / concurrency |
|
||||
| [s03](./s03_permission/) | Permission System | `PermissionRule` / approval pipeline |
|
||||
| [s04](./s04_hooks/) | Hook System | `PreToolUse` / `PostToolUse` / extension points |
|
||||
|
||||
Reference in New Issue
Block a user