feat: add agent for database retrieval
Browse files- services/agent_services.py +22 -3
services/agent_services.py
CHANGED
|
@@ -47,6 +47,11 @@ def create_agent(
|
|
| 47 |
|
| 48 |
|
| 49 |
def create_supervisor_agent(llm: BaseChatModel) -> AgentExecutor:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
assign_to_research_agent = create_handoff_tool(
|
| 51 |
agent_name="research_agent",
|
| 52 |
description="Assign task to a researcher agent.",
|
|
@@ -59,7 +64,11 @@ def create_supervisor_agent(llm: BaseChatModel) -> AgentExecutor:
|
|
| 59 |
|
| 60 |
return create_agent(
|
| 61 |
llm=llm,
|
| 62 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
prompt_name="supervisor_prompt",
|
| 64 |
name="supervisor",
|
| 65 |
)
|
|
@@ -68,9 +77,16 @@ def create_supervisor_agent(llm: BaseChatModel) -> AgentExecutor:
|
|
| 68 |
def create_workflow() -> Callable:
|
| 69 |
llm = create_llm()
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
research_agent = create_agent(
|
| 72 |
llm=llm,
|
| 73 |
-
tools=[
|
| 74 |
prompt_name="web_research_prompt",
|
| 75 |
name="research_agent",
|
| 76 |
)
|
|
@@ -87,11 +103,14 @@ def create_workflow() -> Callable:
|
|
| 87 |
workflow = StateGraph(MessagesState)
|
| 88 |
|
| 89 |
workflow.add_node(
|
| 90 |
-
supervisor_agent,
|
|
|
|
| 91 |
)
|
|
|
|
| 92 |
workflow.add_node(research_agent)
|
| 93 |
workflow.add_node(math_agent)
|
| 94 |
workflow.add_edge(START, "supervisor")
|
|
|
|
| 95 |
workflow.add_edge("research_agent", "supervisor")
|
| 96 |
workflow.add_edge("math_agent", "supervisor")
|
| 97 |
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
def create_supervisor_agent(llm: BaseChatModel) -> AgentExecutor:
|
| 50 |
+
assign_to_retriever_agent = create_handoff_tool(
|
| 51 |
+
agent_name="retriever_agent",
|
| 52 |
+
description="Assign task to a retriever agent for searching through documents.",
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
assign_to_research_agent = create_handoff_tool(
|
| 56 |
agent_name="research_agent",
|
| 57 |
description="Assign task to a researcher agent.",
|
|
|
|
| 64 |
|
| 65 |
return create_agent(
|
| 66 |
llm=llm,
|
| 67 |
+
tools=[
|
| 68 |
+
assign_to_retriever_agent,
|
| 69 |
+
assign_to_research_agent,
|
| 70 |
+
assign_to_math_agent,
|
| 71 |
+
],
|
| 72 |
prompt_name="supervisor_prompt",
|
| 73 |
name="supervisor",
|
| 74 |
)
|
|
|
|
| 77 |
def create_workflow() -> Callable:
|
| 78 |
llm = create_llm()
|
| 79 |
|
| 80 |
+
retriever_agent = create_agent(
|
| 81 |
+
llm=llm,
|
| 82 |
+
tools=[retriever_tool],
|
| 83 |
+
prompt_name="retriever_prompt",
|
| 84 |
+
name="retriever_agent",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
research_agent = create_agent(
|
| 88 |
llm=llm,
|
| 89 |
+
tools=[internet_search, wiki_search, arxiv_search],
|
| 90 |
prompt_name="web_research_prompt",
|
| 91 |
name="research_agent",
|
| 92 |
)
|
|
|
|
| 103 |
workflow = StateGraph(MessagesState)
|
| 104 |
|
| 105 |
workflow.add_node(
|
| 106 |
+
supervisor_agent,
|
| 107 |
+
destinations=("retriever_agent", "research_agent", "math_agent", END),
|
| 108 |
)
|
| 109 |
+
workflow.add_node(retriever_agent)
|
| 110 |
workflow.add_node(research_agent)
|
| 111 |
workflow.add_node(math_agent)
|
| 112 |
workflow.add_edge(START, "supervisor")
|
| 113 |
+
workflow.add_edge("retriever_agent", "supervisor")
|
| 114 |
workflow.add_edge("research_agent", "supervisor")
|
| 115 |
workflow.add_edge("math_agent", "supervisor")
|
| 116 |
|