[AAASM-1181] ✨ (langgraph): Add delegation_reason, ToolNode detection, and config parent-id read#38
Merged
Chisanan232 merged 4 commits intoMay 9, 2026
Conversation
Enriches the lineage context with the reason a child agent was spawned (e.g., langgraph_node:my_node, langgraph_tool:retriever) for finer-grained audit and observability.
…agent-id read - _extract_agent_id_from_runnable_config: reads aaasm_agent_id from RunnableConfig.configurable - _is_tool_node: duck-type detector (tools_by_name dict, no nodes attr) - _wrap_tool_node_subgraphs: intercepts compiled-subgraph tools inside ToolNode, setting spawned_by_tool + delegation_reason=langgraph_tool:<name> - _make_subgraph_spawn_wrapper: accepts spawned_by_tool + delegation_reason params - _wrap_node_map: checks _is_tool_node before callable() (ToolNode is also callable); sets delegation_reason=langgraph_node:<name> for plain compiled-subgraph nodes
…tests Covers delegation_reason default None, explicit value storage, and the init_assembly auto-population of parent_agent_id/depth/spawned_by_tool from the active _SPAWN_CTX ContextVar.
…nd config reader New test classes: TestExtractAgentIdFromRunnableConfig, TestIsToolNode, TestWrapToolNodeSubgraphs, TestWrapNodeMapDelegationReason. Updated TestMakeSubgraphSpawnWrapper to assert delegation_reason propagation and the plain-subgraph node spawned_by_tool=None behavior.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
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
delegation_reason: str | Nonefield toSpawnContextto record the context in which a child agent was spawned (e.g.,langgraph_node:my_node,langgraph_tool:retriever)_extract_agent_id_from_runnable_configto readaaasm_agent_idfrom LangGraph'sRunnableConfig.configurable_is_tool_nodeduck-type detector for LangGraphToolNodeobjects_wrap_tool_node_subgraphsto intercept compiled-subgraph tools nested inside aToolNode, settingspawned_by_tool+delegation_reason=langgraph_tool:<tool_name>_wrap_node_mapto check_is_tool_nodebeforecallable()(ToolNode is also callable) and setsdelegation_reason=langgraph_node:<node_name>for plain compiled-subgraph nodesMotivation
Closes AAASM-1181. This is a follow-up to PR #37 which delivered the ContextVar backbone. The
delegation_reasonfield enables downstream audit and observability to distinguish how a child agent was spawned — whether from a plain subgraph node, a tool call via ToolNode, or another mechanism.How to verify
All 265 tests pass, ruff clean, mypy clean on changed files.
Closes #AAASM-1181