Skip to content

feat: implement multi-hop pathway traversal for deeper mechanistic reasoning#153

Open
bhavyakeerthi3 wants to merge 7 commits intoreactome:mainfrom
bhavyakeerthi3:feat/multi-hop-pathway-traversal
Open

feat: implement multi-hop pathway traversal for deeper mechanistic reasoning#153
bhavyakeerthi3 wants to merge 7 commits intoreactome:mainfrom
bhavyakeerthi3:feat/multi-hop-pathway-traversal

Conversation

@bhavyakeerthi3
Copy link
Copy Markdown

@bhavyakeerthi3 bhavyakeerthi3 commented Mar 15, 2026

Fixes #152

Description

This PR implements recursive traversal in ReactomeTopologyTool. Previously the tool fetched only immediate local context direct inputs, outputs, and one level of preceding events. This enhancement allows the agent to follow both causal and hierarchical links recursively, providing significantly deeper mechanistic context.

Changes

  • Recursive Traversal: Added recursive helper to get_flow_context to follow multi-step hops through the Reactome graph
  • Hierarchical & Causal Support: Follows both hasEvent (Pathway → Sub-segment) and precedingEvent (Reaction → Upstream trigger)
  • Cycle Detection: Prevents infinite loops in circular biological network structures
  • Token Safety: max_depth=2 default with per-level breadth cap of 3 events — balances context richness against LLM window limits

Impact

The agent can now answer complex process-oriented queries like "What triggers this cascade?" by tracing causal flow across multiple hops in the Reactome pathway network — rather than seeing only the immediate reaction context.

Verification

  • Hierarchical expansion: Apoptosis (R-HSA-109581) correctly expanded into sub-pathways
  • Upstream traversal: Causal preceding events traced for reaction R-HSA-111452

Files Affected

  • src/tools/reactome_topology.py
  • tests/test_flow_reasoning.py

…y data between nodes

Without this field, LangGraph silently drops the topology data returned
by identify_flow() before verify_mechanism() can read it, making the
entire topological flow reasoning feature a no-op in production.

Also adds a regression test (test_flow_context_in_state) to ensure
the field is never accidentally removed.
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.

feat: implement multi-hop pathway traversal for deeper mechanistic reasoning

1 participant