diff --git a/agent_loop.py b/agent_loop.py index 7afb5850..ee4fdab5 100644 --- a/agent_loop.py +++ b/agent_loop.py @@ -46,7 +46,15 @@ def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema, {"role": "user", "content": initial_user_content if initial_user_content is not None else user_input} ] turn = 0; handler.max_turns = max_turns - _hook('agent_before', locals()) + _ctx = _hook('agent_before', locals()) # plugins may return dict to override system_prompt/user_input + if isinstance(_ctx, dict): + if 'system_prompt' in _ctx: + system_prompt = _ctx['system_prompt'] + messages[0]['content'] = system_prompt + if _ctx.get('initial_user_content') is not None: + messages[1]['content'] = _ctx['initial_user_content'] + elif 'user_input' in _ctx and initial_user_content is None: + messages[1]['content'] = _ctx['user_input'] while turn < handler.max_turns: turn += 1; turnstr = f'LLM Running (Turn {turn}) ...' if handler.parent.task_dir: turnstr = f'Turn {turn} ...'