-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagents.py
More file actions
81 lines (68 loc) · 3 KB
/
agents.py
File metadata and controls
81 lines (68 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
from dataclasses import dataclass
from langgraph.graph.state import CompiledStateGraph
from langgraph.pregel import Pregel
from agents.bg_task_agent.bg_task_agent import bg_task_agent
from agents.chatbot import chatbot
from agents.command_agent import command_agent
from agents.interrupt_agent import interrupt_agent
from agents.knowledge_base_agent import kb_agent
from agents.langgraph_supervisor_agent import langgraph_supervisor_agent
from agents.langgraph_supervisor_hierarchy_agent import langgraph_supervisor_hierarchy_agent
from agents.rag_assistant import rag_assistant
from agents.research_assistant import research_assistant
from agents.travel_planner_functional import travel_planner, get_history_helper, save_history_helper
from core.settings import settings
from schema import AgentInfo
logger = logging.getLogger(__name__)
DEFAULT_AGENT = settings.DEFAULT_AGENT
logger.info(f"Default Agent: {DEFAULT_AGENT}")
# Type alias to handle LangGraph's different agent patterns
# - @entrypoint functions return Pregel
# - StateGraph().compile() returns CompiledStateGraph
AgentGraph = CompiledStateGraph | Pregel
@dataclass
class Agent:
description: str
graph: AgentGraph
agents: dict[str, Agent] = {
"chatbot": Agent(description="A simple chatbot.", graph=chatbot),
"research-assistant": Agent(
description="A research assistant with web search and calculator.", graph=research_assistant
),
"rag-assistant": Agent(
description="A RAG assistant with access to information in a database.", graph=rag_assistant
),
"travel-planner": Agent(
description="A travel planner powered by NLU/RAG, with fallback to research assistant.",
graph=travel_planner,
),
"get-history-helper": Agent(
description="Helper to retrieve full message history from checkpoint.",
graph=get_history_helper,
),
"save-history-helper": Agent(
description="Helper to save messages to checkpoint without processing.",
graph=save_history_helper,
),
"command-agent": Agent(description="A command agent.", graph=command_agent),
"bg-task-agent": Agent(description="A background task agent.", graph=bg_task_agent),
"langgraph-supervisor-agent": Agent(
description="A langgraph supervisor agent", graph=langgraph_supervisor_agent
),
"langgraph-supervisor-hierarchy-agent": Agent(
description="A langgraph supervisor agent with a nested hierarchy of agents",
graph=langgraph_supervisor_hierarchy_agent,
),
"interrupt-agent": Agent(description="An agent the uses interrupts.", graph=interrupt_agent),
"knowledge-base-agent": Agent(
description="A retrieval-augmented generation agent using Amazon Bedrock Knowledge Base",
graph=kb_agent,
),
}
def get_agent(agent_id: str) -> AgentGraph:
return agents[agent_id].graph
def get_all_agent_info() -> list[AgentInfo]:
return [
AgentInfo(key=agent_id, description=agent.description) for agent_id, agent in agents.items()
]