Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- [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)
- [Command: a new tool for building multi-agent architectures in LangGraph](https://www.youtube.com/watch?v=6BJDKf90L9A)
- [masamasa59/genai-agent-advanced-book > chapter6](https://github.com/masamasa59/genai-agent-advanced-book/blob/main/chapter6/arxiv_researcher/agent/paper_search_agent.py)
- [langchain-ai/deepagents](https://github.com/langchain-ai/deepagents)
- [Custom UI for Deep Agents](https://github.com/langchain-ai/deep-agents-ui)

### Sample Codes

Expand Down
1 change: 1 addition & 0 deletions langgraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"chat_with_tools_agent": "template_langgraph.agents.chat_with_tools_agent.agent:graph",
"demo_agents_parallel_rag_agent": "template_langgraph.agents.demo_agents.parallel_rag_agent.agent:graph",
"demo_agents_multi_agent": "template_langgraph.agents.demo_agents.multi_agent:graph",
"demo_agents_research_deep_agent": "template_langgraph.agents.demo_agents.research_deep_agent:graph",
"demo_agents_weather_agent": "template_langgraph.agents.demo_agents.weather_agent:graph",
"image_classifier_agent": "template_langgraph.agents.image_classifier_agent.agent:graph",
"issue_formatter_agent": "template_langgraph.agents.issue_formatter_agent.agent:graph",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ruff: noqa
from template_langgraph.agents.demo_agents.deep_agent_core.graph import create_deep_agent
from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState
from template_langgraph.agents.demo_agents.deep_agent_core.sub_agent import SubAgent
80 changes: 80 additions & 0 deletions template_langgraph/agents/demo_agents/deep_agent_core/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ruff: noqa: E501
from collections.abc import Callable, Sequence
from typing import Any, TypeVar

from langchain_core.language_models import LanguageModelLike
from langchain_core.tools import BaseTool
from langgraph.prebuilt import create_react_agent
from langgraph.types import Checkpointer

from template_langgraph.agents.demo_agents.deep_agent_core.state import DeepAgentState
from template_langgraph.agents.demo_agents.deep_agent_core.sub_agent import SubAgent, _create_task_tool
from template_langgraph.agents.demo_agents.deep_agent_core.tools import (
edit_file,
ls,
read_file,
write_file,
write_todos,
)
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper

StateSchema = TypeVar("StateSchema", bound=DeepAgentState)
StateSchemaType = type[StateSchema]

base_prompt = """You have access to a number of standard tools

## `write_todos`

You have access to the `write_todos` tools to help you manage and plan tasks. Use these tools VERY frequently to ensure that you are tracking your tasks and giving the user visibility into your progress.
These tools are also EXTREMELY helpful for planning tasks, and for breaking down larger complex tasks into smaller steps. If you do not use this tool when planning, you may forget to do important tasks - and that is unacceptable.

It is critical that you mark todos as completed as soon as you are done with a task. Do not batch up multiple tasks before marking them as completed.
## `task`

- When doing web search, prefer to use the `task` tool in order to reduce context usage."""


def create_deep_agent(
tools: Sequence[BaseTool | Callable | dict[str, Any]],
instructions: str,
model: str | LanguageModelLike | None = None,
subagents: list[SubAgent] = None,
state_schema: StateSchemaType | None = None,
config_schema: type[Any] | None = None,
checkpointer: Checkpointer | None = None,
):
"""Create a deep agent.

This agent will by default have access to a tool to write todos (write_todos),
and then four file editing tools: write_file, ls, read_file, edit_file.

Args:
tools: The additional tools the agent should have access to.
instructions: The additional instructions the agent should have. Will go in
the system prompt.
model: The model to use.
subagents: The subagents to use. Each subagent should be a dictionary with the
following keys:
- `name`
- `description` (used by the main agent to decide whether to call the sub agent)
- `prompt` (used as the system prompt in the subagent)
- (optional) `tools`
state_schema: The schema of the deep agent. Should subclass from template_langgraph.agents.demo_agents.deep_agent_coretate
Copy link
Preview

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the docstring: 'deep_agent_coretate' should be 'deep_agent_core.state'.

Suggested change
state_schema: The schema of the deep agent. Should subclass from template_langgraph.agents.demo_agents.deep_agent_coretate
state_schema: The schema of the deep agent. Should subclass from template_langgraph.agents.demo_agents.deep_agent_core.state

Copilot uses AI. Check for mistakes.

config_schema: The schema of the deep agent.
checkpointer: Optional checkpointer for persisting agent state between runs.
"""
prompt = instructions + base_prompt
built_in_tools = [write_todos, write_file, read_file, ls, edit_file]
if model is None:
model = AzureOpenAiWrapper().chat_model
state_schema = state_schema or DeepAgentState
task_tool = _create_task_tool(list(tools) + built_in_tools, instructions, subagents or [], model, state_schema)
all_tools = built_in_tools + list(tools) + [task_tool]
return create_react_agent(
model,
prompt=prompt,
tools=all_tools,
state_schema=state_schema,
config_schema=config_schema,
checkpointer=checkpointer,
)
Loading