mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-07 14:52:39 +02:00
Add multi_agent_chat routing tools and supervisor routing composition.
This commit is contained in:
parent
0fcb2acfdc
commit
f1a5f1c683
3 changed files with 83 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
||||||
|
"""Supervisor routing: domain-agent wrappers and composed routing tool lists."""
|
||||||
|
|
||||||
|
from app.agents.multi_agent_chat.routing.from_domain_agents import routing_tools_from_domain_agents
|
||||||
|
from app.agents.multi_agent_chat.routing.supervisor_routing import build_supervisor_routing_tools
|
||||||
|
from app.agents.multi_agent_chat.shared.invoke_output import extract_last_assistant_text
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"build_supervisor_routing_tools",
|
||||||
|
"extract_last_assistant_text",
|
||||||
|
"routing_tools_from_domain_agents",
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
"""LangChain ``@tool`` wrappers that invoke compiled domain-agent graphs (supervisor-facing only)."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from langchain_core.tools import BaseTool, tool
|
||||||
|
|
||||||
|
from app.agents.multi_agent_chat.shared.invoke_output import extract_last_assistant_text
|
||||||
|
|
||||||
|
|
||||||
|
def routing_tools_from_domain_agents(
|
||||||
|
*,
|
||||||
|
gmail_domain_agent: Any,
|
||||||
|
calendar_domain_agent: Any,
|
||||||
|
) -> list[BaseTool]:
|
||||||
|
"""Build ``gmail`` / ``calendar`` tools that invoke the given graphs (factory, not import-time exports)."""
|
||||||
|
|
||||||
|
@tool(
|
||||||
|
"gmail",
|
||||||
|
description=(
|
||||||
|
"Route Gmail-related work to the Gmail sub-agent. "
|
||||||
|
"Pass a clear natural-language task."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def call_gmail_agent(task: str) -> str:
|
||||||
|
result = gmail_domain_agent.invoke(
|
||||||
|
{"messages": [{"role": "user", "content": task}]}
|
||||||
|
)
|
||||||
|
return extract_last_assistant_text(result)
|
||||||
|
|
||||||
|
@tool(
|
||||||
|
"calendar",
|
||||||
|
description=(
|
||||||
|
"Route Google Calendar work to the Calendar sub-agent. "
|
||||||
|
"Pass a clear natural-language task."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def call_calendar_agent(task: str) -> str:
|
||||||
|
result = calendar_domain_agent.invoke(
|
||||||
|
{"messages": [{"role": "user", "content": task}]}
|
||||||
|
)
|
||||||
|
return extract_last_assistant_text(result)
|
||||||
|
|
||||||
|
return [call_gmail_agent, call_calendar_agent]
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
"""Compose domain agents + connector tool lists into supervisor ``gmail`` / ``calendar`` routing tools."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from langchain_core.language_models import BaseChatModel
|
||||||
|
from langchain_core.tools import BaseTool
|
||||||
|
|
||||||
|
from app.agents.multi_agent_chat.calendar import build_calendar_domain_agent
|
||||||
|
from app.agents.multi_agent_chat.gmail import build_gmail_domain_agent
|
||||||
|
from app.agents.multi_agent_chat.routing.from_domain_agents import routing_tools_from_domain_agents
|
||||||
|
|
||||||
|
|
||||||
|
def build_supervisor_routing_tools(
|
||||||
|
llm: BaseChatModel,
|
||||||
|
*,
|
||||||
|
gmail_tools: Sequence[BaseTool] | None = None,
|
||||||
|
calendar_tools: Sequence[BaseTool] | None = None,
|
||||||
|
) -> list[BaseTool]:
|
||||||
|
"""Domain agents (with their connector tools) → ``gmail`` / ``calendar`` routing tools."""
|
||||||
|
gmail_domain_agent = build_gmail_domain_agent(llm, list(gmail_tools or []))
|
||||||
|
calendar_domain_agent = build_calendar_domain_agent(llm, list(calendar_tools or []))
|
||||||
|
return routing_tools_from_domain_agents(
|
||||||
|
gmail_domain_agent=gmail_domain_agent,
|
||||||
|
calendar_domain_agent=calendar_domain_agent,
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue