Skip to content

feat(agent): expose approval_callback in create_agent()#31

Open
caoergou wants to merge 1 commit into
UnicomAI:mainfrom
caoergou:feat/approval-callback-in-create-agent
Open

feat(agent): expose approval_callback in create_agent()#31
caoergou wants to merge 1 commit into
UnicomAI:mainfrom
caoergou:feat/approval-callback-in-create-agent

Conversation

@caoergou

@caoergou caoergou commented Jun 8, 2026

Copy link
Copy Markdown

Summary

AgentMiddleware and LangChainSubagentRunner both accept an approval_callback parameter for human-in-the-loop approvals, but create_agent() — the only public factory — never accepted or forwarded it. This made the NEEDS_APPROVAL flow defined by SafetyRule completely inaccessible: any tool that returned PermissionResult.NEEDS_APPROVAL would always be silently denied, regardless of what callers wanted.

Changes:

  • Add approval_callback: ApprovalCallback | None = None to create_agent() signature with docstring
  • Thread it through to AgentMiddleware (root agent) and LangChainSubagentRunner (subagents)
  • Add ApprovalCallback to the TYPE_CHECKING import block in agent.py (avoids circular import at runtime)
  • Add tests verifying the parameter is present with None default and is correctly stored by LangChainSubagentRunner

Test plan

  • make lint — passes (ruff + mypy strict)
  • make test — all 1060 unit tests pass
  • Manual: construct a SafetyRule that returns NEEDS_APPROVAL and pass an approval_callback to create_agent() — callback is now reachable

Related

Complements the permission_gate parameter already exposed in create_agent(). The approval_callback is the interactive layer that sits on top of the permission gate.

AgentMiddleware and LangChainSubagentRunner both support a
human-in-the-loop approval_callback, but create_agent() — the only
public entry point — never accepted or forwarded it, making the
NEEDS_APPROVAL flow completely inaccessible to callers.

Thread the new optional parameter through to both AgentMiddleware
(root agent) and LangChainSubagentRunner (subagents) so callers can
implement interactive approval without forking the factory.

Add tests that verify the parameter exists with a None default and
that LangChainSubagentRunner stores it correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant