Skip to content

Commit 5b4b29f

Browse files
committed
modify implementation
1 parent 6f358b7 commit 5b4b29f

File tree

10 files changed

+45
-56
lines changed

10 files changed

+45
-56
lines changed

docs/references.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [Combine control flow and state updates with Command](https://langchain-ai.github.io/langgraph/how-tos/graph-api/#combine-control-flow-and-state-updates-with-command)
1414
- [Command: a new tool for building multi-agent architectures in LangGraph](https://www.youtube.com/watch?v=6BJDKf90L9A)
1515
- [masamasa59/genai-agent-advanced-book > chapter6](https://github.com/masamasa59/genai-agent-advanced-book/blob/main/chapter6/arxiv_researcher/agent/paper_search_agent.py)
16+
- [langchain-ai/deepagents](https://github.com/langchain-ai/deepagents)
17+
- [Custom UI for Deep Agents](https://github.com/langchain-ai/deep-agents-ui)
1618

1719
### Sample Codes
1820

langgraph.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"chat_with_tools_agent": "template_langgraph.agents.chat_with_tools_agent.agent:graph",
55
"demo_agents_parallel_rag_agent": "template_langgraph.agents.demo_agents.parallel_rag_agent.agent:graph",
66
"demo_agents_multi_agent": "template_langgraph.agents.demo_agents.multi_agent:graph",
7+
"demo_agents_research_deep_agent": "template_langgraph.agents.demo_agents.research_deep_agent:graph",
78
"demo_agents_weather_agent": "template_langgraph.agents.demo_agents.weather_agent:graph",
89
"image_classifier_agent": "template_langgraph.agents.image_classifier_agent.agent:graph",
910
"issue_formatter_agent": "template_langgraph.agents.issue_formatter_agent.agent:graph",
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from deepagents.graph import create_deep_agent
2-
from deepagents.model import get_default_model
3-
from deepagents.state import DeepAgentState
4-
from deepagents.sub_agent import SubAgent
1+
# ruff: noqa
2+
from template_langgraph.agents.demo_agents.deep_agent_core.graph import create_deep_agent
3+
from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState
4+
from template_langgraph.agents.demo_agents.deep_agent_core.sub_agent import SubAgent

template_langgraph/agents/demo_agents/deep_agent_core/graph.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
# ruff: noqa: E501
12
from collections.abc import Callable, Sequence
23
from typing import Any, TypeVar
34

4-
from deepagents.model import get_default_model
5-
from deepagents.state import DeepAgentState
6-
from deepagents.sub_agent import SubAgent, _create_task_tool
7-
from deepagents.tools import edit_file, ls, read_file, write_file, write_todos
85
from langchain_core.language_models import LanguageModelLike
96
from langchain_core.tools import BaseTool
107
from langgraph.prebuilt import create_react_agent
118
from langgraph.types import Checkpointer
129

10+
from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState
11+
from template_langgraph.agents.demo_agents.deep_agent_core.sub_agent import SubAgent, _create_task_tool
12+
from template_langgraph.agents.demo_agents.deep_agent_core.tools import (
13+
edit_file,
14+
ls,
15+
read_file,
16+
write_file,
17+
write_todos,
18+
)
19+
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper
20+
1321
StateSchema = TypeVar("StateSchema", bound=DeepAgentState)
1422
StateSchemaType = type[StateSchema]
1523

@@ -51,14 +59,14 @@ def create_deep_agent(
5159
- `description` (used by the main agent to decide whether to call the sub agent)
5260
- `prompt` (used as the system prompt in the subagent)
5361
- (optional) `tools`
54-
state_schema: The schema of the deep agent. Should subclass from DeepAgentState
62+
state_schema: The schema of the deep agent. Should subclass from template_langgraph.agents.demo_agents.deep_agent_coretate
5563
config_schema: The schema of the deep agent.
5664
checkpointer: Optional checkpointer for persisting agent state between runs.
5765
"""
5866
prompt = instructions + base_prompt
5967
built_in_tools = [write_todos, write_file, read_file, ls, edit_file]
6068
if model is None:
61-
model = get_default_model()
69+
model = AzureOpenAiWrapper().chat_model
6270
state_schema = state_schema or DeepAgentState
6371
task_tool = _create_task_tool(list(tools) + built_in_tools, instructions, subagents or [], model, state_schema)
6472
all_tools = built_in_tools + list(tools) + [task_tool]

template_langgraph/agents/demo_agents/deep_agent_core/model.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

template_langgraph/agents/demo_agents/deep_agent_core/prompts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: E501
12
WRITE_TODOS_DESCRIPTION = """Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
23
It also helps the user understand the progress of the task and overall progress of their requests.
34

template_langgraph/agents/demo_agents/deep_agent_core/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Todo(TypedDict):
1111
status: Literal["pending", "in_progress", "completed"]
1212

1313

14-
def file_reducer(l, r):
14+
def file_reducer(l, r): # noqa
1515
if l is None:
1616
return r
1717
elif r is None:

template_langgraph/agents/demo_agents/deep_agent_core/sub_agent.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from typing import Annotated, Any, NotRequired
22

3-
from deepagents.prompts import TASK_DESCRIPTION_PREFIX, TASK_DESCRIPTION_SUFFIX
4-
from deepagents.state import DeepAgentState
53
from langchain.chat_models import init_chat_model
64
from langchain_core.messages import ToolMessage
75
from langchain_core.tools import BaseTool, InjectedToolCallId, tool
86
from langgraph.prebuilt import InjectedState, create_react_agent
97
from langgraph.types import Command
108
from typing_extensions import TypedDict
119

10+
from template_langgraph.agents.demo_agents.deep_agent_core.prompts import (
11+
TASK_DESCRIPTION_PREFIX,
12+
TASK_DESCRIPTION_SUFFIX,
13+
)
14+
from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState
15+
1216

1317
class SubAgent(TypedDict):
1418
name: str

template_langgraph/agents/demo_agents/deep_agent_core/tools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
# ruff: noqa: E501
12
from typing import Annotated
23

3-
from deepagents.prompts import (
4-
EDIT_DESCRIPTION,
5-
TOOL_DESCRIPTION,
6-
WRITE_TODOS_DESCRIPTION,
7-
)
8-
from deepagents.state import DeepAgentState, Todo
94
from langchain_core.messages import ToolMessage
105
from langchain_core.tools import InjectedToolCallId, tool
116
from langgraph.prebuilt import InjectedState
127
from langgraph.types import Command
138

9+
from template_langgraph.agents.demo_agents.deep_agent_core.prompts import (
10+
EDIT_DESCRIPTION,
11+
TOOL_DESCRIPTION,
12+
WRITE_TODOS_DESCRIPTION,
13+
)
14+
from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState, Todo
15+
1416

1517
@tool(description=WRITE_TODOS_DESCRIPTION)
1618
def write_todos(todos: list[Todo], tool_call_id: Annotated[str, InjectedToolCallId]) -> Command:

template_langgraph/agents/demo_agents/deep_agent_core/research_agent.py renamed to template_langgraph/agents/demo_agents/research_deep_agent.py

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
import os
2-
from typing import Literal
3-
4-
from deepagents import create_deep_agent
5-
from tavily import TavilyClient
6-
7-
# It's best practice to initialize the client once and reuse it.
8-
tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
9-
10-
11-
# Search tool to use to do research
12-
def internet_search(
13-
query: str,
14-
max_results: int = 5,
15-
topic: Literal["general", "news", "finance"] = "general",
16-
include_raw_content: bool = False,
17-
):
18-
"""Run a web search"""
19-
search_docs = tavily_client.search(
20-
query,
21-
max_results=max_results,
22-
include_raw_content=include_raw_content,
23-
topic=topic,
24-
)
25-
return search_docs
26-
1+
# ruff: noqa: E501
2+
from template_langgraph.agents.demo_agents.deep_agent_core import create_deep_agent
3+
from template_langgraph.tools.common import get_default_tools
274

285
sub_research_prompt = """You are a dedicated researcher. Your job is to conduct research based on the users questions.
296
@@ -35,7 +12,6 @@ def internet_search(
3512
"name": "research-agent",
3613
"description": "Used to research more in depth questions. Only give this researcher one topic at a time. Do not pass multiple sub questions to this researcher. Instead, you should break down a large topic into the necessary components, and then call multiple research agents in parallel, one for each sub question.",
3714
"prompt": sub_research_prompt,
38-
"tools": ["internet_search"],
3915
}
4016

4117
sub_critique_prompt = """You are a dedicated editor. You are being tasked to critique a report.
@@ -152,14 +128,14 @@ def internet_search(
152128
153129
You have access to a few tools.
154130
155-
## `internet_search`
131+
## `search_ai_search`
156132
157-
Use this to run an internet search for a given query. You can specify the number of results, the topic, and whether raw content should be included.
133+
Use this to run an Azure AI Search for getting KABUTO related information. You can specify the number of results, the topic, and whether raw content should be included.
158134
"""
159135

160136
# Create the agent
161-
agent = create_deep_agent(
162-
[internet_search],
163-
research_instructions,
137+
graph = create_deep_agent(
138+
tools=get_default_tools(),
139+
instructions=research_instructions,
164140
subagents=[critique_sub_agent, research_sub_agent],
165141
).with_config({"recursion_limit": 1000})

0 commit comments

Comments
 (0)