Skip to content

Instantly share code, notes, and snippets.

@kennethleungty
Created December 5, 2025 15:28
Show Gist options
  • Select an option

  • Save kennethleungty/1ff479c72030acafe05672c8b9b9370b to your computer and use it in GitHub Desktop.

Select an option

Save kennethleungty/1ff479c72030acafe05672c8b9b9370b to your computer and use it in GitHub Desktop.
def should_continue(
state: SupervisorState,
) -> Literal["transaction_history_agent", "property_profile_agent", "end"]:
"""Extract routing decision from supervisor's message.
Looks for agent names in the supervisor's latest message to determine routing.
Returns "end" if supervisor provides a direct response (no routing needed).
"""
# Find latest supervisor message
for msg in reversed(state["messages"]):
if (
isinstance(msg, AIMessage)
and hasattr(msg, "name")
and msg.name == "supervisor"
):
content = msg.content.strip().lower()
# Check for agent names in content
if "transaction_history_agent" in content:
return "transaction_history_agent"
elif "property_profile_agent" in content:
return "property_profile_agent"
return "end" # No agent name found - supervisor handled directly
return "end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment