feat(agent): expose approval_callback in create_agent()#31
Open
caoergou wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AgentMiddlewareandLangChainSubagentRunnerboth accept anapproval_callbackparameter for human-in-the-loop approvals, butcreate_agent()— the only public factory — never accepted or forwarded it. This made theNEEDS_APPROVALflow defined bySafetyRulecompletely inaccessible: any tool that returnedPermissionResult.NEEDS_APPROVALwould always be silently denied, regardless of what callers wanted.Changes:
approval_callback: ApprovalCallback | None = Nonetocreate_agent()signature with docstringAgentMiddleware(root agent) andLangChainSubagentRunner(subagents)ApprovalCallbackto theTYPE_CHECKINGimport block inagent.py(avoids circular import at runtime)Nonedefault and is correctly stored byLangChainSubagentRunnerTest plan
make lint— passes (ruff + mypy strict)make test— all 1060 unit tests passSafetyRulethat returnsNEEDS_APPROVALand pass anapproval_callbacktocreate_agent()— callback is now reachableRelated
Complements the
permission_gateparameter already exposed increate_agent(). Theapproval_callbackis the interactive layer that sits on top of the permission gate.