Bug: Plugin hooks cannot modify context due to ignored return value
Description
The plugin hook system in agent_loop.py calls _hook('agent_before', locals()) but does not handle the return value. This prevents plugins from modifying the agent context (e.g., system_prompt), making the hook mechanism non-functional for context modification use cases.
Current Behavior
When a plugin registers an agent_before hook and returns a modified context:
# plugins/example_plugin.py
from plugins import hooks
@hooks.register('agent_before')
def modify_context(ctx):
ctx['system_prompt'] += '\n\n[Additional Context]\n...'
return ctx
The modified system_prompt is ignored because agent_loop.py does not use the return value:
# agent_loop.py (current)
_hook('agent_before', locals()) # Return value is discarded
Expected Behavior
Plugins should be able to modify the agent context by returning an updated dictionary from their hook handlers. The hook system should apply these modifications.
Steps to Reproduce
- Create a plugin that modifies
system_prompt in an agent_before hook
- Register the plugin using
@hooks.register('agent_before')
- Run an agent session
- Observe that the
system_prompt modifications are not applied
Root Cause
In agent_loop.py line 49 (commit 3b7e6ab), the hook is called but the return value is not captured or processed:
def agent_runner_loop(client, system_prompt, user_input, handler, tools_schema,
max_turns=40, verbose=True, initial_user_content=None, yield_info=False):
messages = [
{"role": "system", "content": system_prompt},
{"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()) # ❌ Return value ignored
while turn < handler.max_turns:
# ...
Impact
- Plugins cannot modify agent context (system prompt, user input, etc.)
- The hook mechanism is only useful for read-only operations (logging, metrics)
- Limits the extensibility of the plugin system
Environment
- GenericAgent version: main branch (commit 3b7e6ab and later)
- Python version: 3.x
- OS: macOS / Linux / Windows
Proposed Solution
See PR #XXX for a fix that:
- Captures the hook return value
- Applies modifications to the context when a dict is returned
- Maintains backward compatibility with hooks that don't return values
Bug: Plugin hooks cannot modify context due to ignored return value
Description
The plugin hook system in
agent_loop.pycalls_hook('agent_before', locals())but does not handle the return value. This prevents plugins from modifying the agent context (e.g.,system_prompt), making the hook mechanism non-functional for context modification use cases.Current Behavior
When a plugin registers an
agent_beforehook and returns a modified context:The modified
system_promptis ignored becauseagent_loop.pydoes not use the return value:Expected Behavior
Plugins should be able to modify the agent context by returning an updated dictionary from their hook handlers. The hook system should apply these modifications.
Steps to Reproduce
system_promptin anagent_beforehook@hooks.register('agent_before')system_promptmodifications are not appliedRoot Cause
In
agent_loop.pyline 49 (commit 3b7e6ab), the hook is called but the return value is not captured or processed:Impact
Environment
Proposed Solution
See PR #XXX for a fix that: