mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-06-20 20:23:36 +08:00
Merge pull request #320 from hardness1020/fix/s04-hooks-problem-block-idiom
fix(s04): align problem code block with early-continue idiom
This commit is contained in:
@@ -21,13 +21,14 @@ def agent_loop(messages):
|
|||||||
while True:
|
while True:
|
||||||
# ... LLM call ...
|
# ... LLM call ...
|
||||||
for block in response.content:
|
for block in response.content:
|
||||||
if block.type == "tool_use":
|
if block.type != "tool_use":
|
||||||
log_to_file(block) # added a line
|
continue
|
||||||
check_permission(block) # added a line
|
log_to_file(block) # added a line
|
||||||
notify_slack(block) # added another line
|
check_permission(block) # added a line
|
||||||
output = execute(block)
|
notify_slack(block) # added another line
|
||||||
auto_git_add(block) # yet another line
|
output = execute(block)
|
||||||
# ... the loop is unrecognizable
|
auto_git_add(block) # yet another line
|
||||||
|
# ... the loop is unrecognizable
|
||||||
```
|
```
|
||||||
|
|
||||||
What you want to extend is the Agent's behavior, but what you're modifying is the loop itself. The loop should be a stable core; extensions should hang on the outside.
|
What you want to extend is the Agent's behavior, but what you're modifying is the loop itself. The loop should be a stable core; extensions should hang on the outside.
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ def agent_loop(messages):
|
|||||||
while True:
|
while True:
|
||||||
# ... LLM call ...
|
# ... LLM call ...
|
||||||
for block in response.content:
|
for block in response.content:
|
||||||
if block.type == "tool_use":
|
if block.type != "tool_use":
|
||||||
log_to_file(block) # 一行追加
|
continue
|
||||||
check_permission(block) # 一行追加
|
log_to_file(block) # 一行追加
|
||||||
notify_slack(block) # さらに一行追加
|
check_permission(block) # 一行追加
|
||||||
output = execute(block)
|
notify_slack(block) # さらに一行追加
|
||||||
auto_git_add(block) # さらに一行追加
|
output = execute(block)
|
||||||
# ... もうループが見えない
|
auto_git_add(block) # さらに一行追加
|
||||||
|
# ... もうループが見えない
|
||||||
```
|
```
|
||||||
|
|
||||||
拡張したいのは Agent の振る舞いなのに、変更しているのはループそのもの。ループは安定した核心であるべき。拡張は外側に掛ける。
|
拡張したいのは Agent の振る舞いなのに、変更しているのはループそのもの。ループは安定した核心であるべき。拡張は外側に掛ける。
|
||||||
|
|||||||
@@ -21,13 +21,14 @@ def agent_loop(messages):
|
|||||||
while True:
|
while True:
|
||||||
# ... LLM call ...
|
# ... LLM call ...
|
||||||
for block in response.content:
|
for block in response.content:
|
||||||
if block.type == "tool_use":
|
if block.type != "tool_use":
|
||||||
log_to_file(block) # 加一行
|
continue
|
||||||
check_permission(block) # 加一行
|
log_to_file(block) # 加一行
|
||||||
notify_slack(block) # 又加一行
|
check_permission(block) # 加一行
|
||||||
output = execute(block)
|
notify_slack(block) # 又加一行
|
||||||
auto_git_add(block) # 再加一行
|
output = execute(block)
|
||||||
# ... 很快循环就认不出来了
|
auto_git_add(block) # 再加一行
|
||||||
|
# ... 很快循环就认不出来了
|
||||||
```
|
```
|
||||||
|
|
||||||
你想扩展的是 Agent 的行为,但你改的却是循环本身。循环应该是一个稳定的核心,扩展应该挂在外面。
|
你想扩展的是 Agent 的行为,但你改的却是循环本身。循环应该是一个稳定的核心,扩展应该挂在外面。
|
||||||
|
|||||||
Reference in New Issue
Block a user