Skip to content

Commit d17ae18

Browse files
author
Hanson Mei
committed
fix: Handle hook return values to enable context modification
The plugin hook system calls _hook('agent_before', locals()) but was not handling the return value. This prevented plugins from modifying the agent context (e.g., system_prompt). This fix: - Captures the hook return value - Applies modifications when a dict is returned - Maintains backward compatibility with hooks that don't return values Fixes #537
1 parent 071fb6e commit d17ae18

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

agent_loop.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
4646
{"role": "user", "content": initial_user_content if initial_user_content is not None else user_input}
4747
]
4848
turn = 0; handler.max_turns = max_turns
49-
_hook('agent_before', locals())
49+
result = _hook('agent_before', locals())
50+
if isinstance(result, dict):
51+
# Hook 可能修改了 locals,需要更新变量
52+
if 'system_prompt' in result:
53+
messages[0]['content'] = result['system_prompt']
5054
while turn < handler.max_turns:
5155
turn += 1; turnstr = f'LLM Running (Turn {turn}) ...'
5256
if handler.parent.task_dir: turnstr = f'Turn {turn} ...'

0 commit comments

Comments
 (0)