hermes - ✅(Solved) Fix feat(run_agent): add approval_callback parameter to AIAgent constructor [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#11811Fetched 2026-04-18 05:58:46
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Add approval_callback as a constructor parameter to AIAgent in run_agent.py. This allows SDK users to provide an approval callback without manually managing the global terminal_tool._approval_callback state.

Error Message

This is error-prone and exposes implementation details to SDK users.

Root Cause

Add approval_callback as a constructor parameter to AIAgent in run_agent.py. This allows SDK users to provide an approval callback without manually managing the global terminal_tool._approval_callback state.

Fix Action

Fixed

PR fix notes

PR #11815: feat(run_agent): add approval_callback parameter to AIAgent

Description (problem / solution / changelog)

Summary

Add approval_callback as a constructor parameter to AIAgent for clean SDK usage. Previously, setting up approval callbacks for programmatic agent sessions required manually managing global terminal_tool._approval_callback state. This change encapsulates that complexity.

What changed

  • run_agent.py:
    • Add approval_callback: callable = None parameter to AIAgent.__init__
    • Store as self.approval_callback
    • Auto-register via register_gateway_notify() before agent loop using context manager
    • Cleanup in finally block guaranteed

How to test

from run_agent import AIAgent

agent = AIAgent(
    model="gpt-4",
    approval_callback=lambda req: {"approved": True, "message": "Auto-approved"}
)
agent.run_conversation("Hello")

Platforms tested

  • macOS (Darwin 25.3.0)

Related

  • Relates to #8081 (ACP approval callback scoping)
  • Complementary to PR #9157 (task-scoped approval registry)

Closes #11811

Changed files

  • gateway/config.py (modified, +9/-1)
  • gateway/run.py (modified, +14/-2)
  • hermes_cli/plugins.py (modified, +29/-12)
  • run_agent.py (modified, +48/-2)
  • tools/approval.py (modified, +6/-1)
  • tools/terminal_tool.py (modified, +17/-0)
RAW_BUFFERClick to expand / collapse

Summary

Add approval_callback as a constructor parameter to AIAgent in run_agent.py. This allows SDK users to provide an approval callback without manually managing the global terminal_tool._approval_callback state.

Motivation

Currently, setting up approval callbacks for programmatic agent sessions requires:

  1. Manually calling set_approval_callback() before running
  2. Manually restoring the previous callback after running
  3. Managing session keys through set_current_session_key()

This is error-prone and exposes implementation details to SDK users.

Changes

  • run_agent.py:
    • Add approval_callback: callable = None parameter to AIAgent.__init__
    • Store as self.approval_callback
    • Register callback before agent loop using context manager pattern
    • Uses register_gateway_notify() for session-scoped registration

Related

  • Relates to #8081 (ACP approval callback scoping)
  • Complementary to PR #9157 (task-scoped approval registry)

extent analysis

TL;DR

Add an approval_callback parameter to the AIAgent constructor in run_agent.py to simplify approval callback management for SDK users.

Guidance

  • Review the changes in run_agent.py to ensure the approval_callback parameter is correctly added to AIAgent.__init__ and stored as self.approval_callback.
  • Verify that the context manager pattern is used to register the callback before the agent loop, utilizing register_gateway_notify() for session-scoped registration.
  • Test the updated AIAgent class to confirm that approval callbacks can be provided without manual management of global state.
  • Check the related issues (#8081 and #9157) to understand the broader context and potential interactions with other approval callback mechanisms.

Example

class AIAgent:
    def __init__(self, ..., approval_callback: callable = None):
        ...
        self.approval_callback = approval_callback
        ...

Notes

This change aims to simplify approval callback management for SDK users, but its effectiveness depends on correct implementation and testing.

Recommendation

Apply the proposed workaround by adding the approval_callback parameter to AIAgent.__init__, as it directly addresses the motivation and summary provided.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix feat(run_agent): add approval_callback parameter to AIAgent constructor [1 pull requests, 1 participants]