Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e154953
feat(deepagents, code): lean system prompt by default, restorable
nick-hollon-lc Jul 20, 2026
ce23402
refactor(deepagents, code): make _builtin_middleware_prompts private
nick-hollon-lc Jul 20, 2026
8d71dde
fix(deepagents, quickjs): keep skills/memory prompts on the lean default
nick-hollon-lc Jul 20, 2026
404d8f0
fix(deepagents): keep filesystem host-path routing when prose is supp…
nick-hollon-lc Jul 20, 2026
3ac886f
refactor(deepagents, code): public trim_duplicate_tool_prompts flag
nick-hollon-lc Jul 20, 2026
a08b327
refactor(deepagents, code): trim duplicate tool prose unconditionally
nick-hollon-lc Jul 21, 2026
36a22cd
refactor(deepagents): move essential trimmed guidance into tool descr…
nick-hollon-lc Jul 21, 2026
40880b3
fix(deepagents): correct offloaded-result grep guidance for artifacts…
nick-hollon-lc Jul 21, 2026
688d82c
refactor(deepagents): trim tool prose via lean middleware defaults
nick-hollon-lc Jul 21, 2026
cb90572
refactor(deepagents): delete the preserved built-in tool-prompt const…
nick-hollon-lc Jul 21, 2026
fb9c3d1
refactor(deepagents): disable default summarization prompt
nick-hollon-lc Jul 21, 2026
5b50172
refactor(deepagents): delete preserved summarization prompt
nick-hollon-lc Jul 21, 2026
1ab4c4a
test(code): refresh system prompt snapshot
nick-hollon-lc Jul 21, 2026
c9dbda2
chore(quickjs): sync lockfile with deepagents metadata
nick-hollon-lc Jul 21, 2026
4d825bb
fix(deepagents): address prompt middleware review feedback
nick-hollon-lc Jul 22, 2026
5d222b1
Merge remote-tracking branch 'origin/main' into nh/remove-base-system…
nick-hollon-lc Jul 22, 2026
c3c0ad0
Merge remote-tracking branch 'origin/main' into nh/remove-base-system…
nick-hollon-lc Jul 22, 2026
90ab0c5
test(sdk): rename base prompt test names
nick-hollon-lc Jul 22, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -253,53 +253,7 @@ When using the write_todos tool:
The todo list is a planning tool - use it judiciously to avoid overwhelming the user with excessive task tracking.


## `write_todos`

You have access to the `write_todos` tool to help you manage and plan complex objectives.
Use this tool for complex objectives to ensure that you are tracking each necessary step.
This tool is very helpful for planning complex objectives, and for breaking down these larger complex objectives into smaller steps.

It is critical that you mark todos as completed as soon as you are done with a step. Do not batch up multiple steps before marking them as completed.
For simple objectives that only require a few steps, it is better to just complete the objective directly and NOT use this tool.
Writing todos takes time and tokens, use it when it is helpful for managing complex many-step problems! But not for simple few-step requests.

## Important To-Do List Usage Notes to Remember

- The `write_todos` tool should never be called multiple times in parallel.
- Don't be afraid to revise the To-Do list as you go. New information may reveal new tasks that need to be done, or old tasks that are irrelevant.

## Finishing a task

When you finish all work, write your final answer in the message AFTER your last `write_todos` call — not in the same turn as that call. Start the final message with the substantive content the user asked for — the data, computation, summary, or analysis. The user wants the result, not confirmation that the work is done.

## Following Conventions

- Read files before editing — understand existing content before making changes
- Mimic existing style, naming conventions, and patterns

## Filesystem Tools `ls`, `read_file`, `write_file`, `edit_file`, `delete`, `glob`, `grep`

You have access to a filesystem which you can interact with using these tools.
All file paths must start with a /. Follow the tool docs for the available tools, and use pagination (offset/limit) when reading large files.

- ls: list files in a directory (requires absolute path)
- read_file: read a file from the filesystem
- write_file: write to a file in the filesystem
- edit_file: edit a file in the filesystem
- delete: delete a file or directory (recursively) from the filesystem
- glob: find files matching a pattern (e.g., "**/*.py")
- grep: search for text within files

## Large Tool Results

When a tool result is too large, it may be offloaded into the filesystem instead of being returned inline. In those cases, use `read_file` to inspect the saved result in chunks, or use `grep` within `<tmp_path>/dcode-artifacts/large_tool_results/` if you need to search across offloaded tool results and do not know the exact file path. Offloaded tool results are stored under `<tmp_path>/dcode-artifacts/large_tool_results/<tool_call_id>`.

## Execute Tool `execute`

You have access to an `execute` tool for running shell commands in a sandboxed environment.
Use this tool to run commands, scripts, tests, builds, and other shell operations.

- execute: run a shell command in the sandbox (returns output and exit code)

## Shell paths vs. virtual paths

Expand All @@ -316,42 +270,6 @@ Host path mappings:
- `<tmp_path>/dcode-artifacts/conversation_history/` -> `<tmp_path>/.deepagents/conversation_history/` (e.g. `<tmp_path>/dcode-artifacts/conversation_history/dir/x.py` -> `<tmp_path>/.deepagents/conversation_history/dir/x.py`)
- `/dcode-artifacts-fallback/conversation_history/` -> `<tmp_path>/.deepagents/conversation_history/` (e.g. `/dcode-artifacts-fallback/conversation_history/dir/x.py` -> `<tmp_path>/.deepagents/conversation_history/dir/x.py`)

## `task` (subagent spawner)

You have access to a `task` tool to launch short-lived subagents that handle isolated tasks. These agents are ephemeral — they live only for the duration of the task and return a single result.

When to use the task tool:

- When a task is complex and multi-step, and can be fully delegated in isolation
- When a task is independent of other tasks and can run in parallel
- When a task requires focused reasoning or heavy token/context usage that would bloat the orchestrator thread
- When sandboxing improves reliability (e.g. code execution, structured searches, data formatting)
- When you only care about the output of the subagent, and not the intermediate steps (ex. performing a lot of research and then returned a synthesized report, performing a series of computations or lookups to achieve a concise, relevant answer.)

Subagent lifecycle:

1. **Spawn** → Provide clear role, instructions, and expected output
2. **Run** → The subagent completes the task autonomously
3. **Return** → The subagent provides a single structured result
4. **Reconcile** → Incorporate or synthesize the result into the main thread

When NOT to use the task tool:

- If you need to see the intermediate reasoning or steps after the subagent has completed (the task tool hides them)
- If the task is trivial (a few tool calls or simple lookup)
- If delegating does not reduce token usage, complexity, or context switching
- If splitting would add latency without benefit

## Important Task Tool Usage Notes to Remember

- Whenever possible, parallelize the work that you do. This is true for both tool_calls, and for tasks. Whenever you have independent steps to complete - make tool_calls, or kick off tasks (subagents) in parallel to accomplish them faster. This saves time for the user, which is incredibly important.
- Remember to use the `task` tool to silo independent tasks within a multi-part objective.
- You should use the `task` tool whenever you have a complex task that will take multiple steps, and is independent from other tasks that the agent needs to complete. These agents are highly competent and efficient.

Available subagent types:

- general-purpose: General-purpose agent for researching complex questions, searching for files and content, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you. This agent has access to all tools as the main agent.

## Goal and Rubric Tools

Use `get_rubric` to inspect active acceptance criteria before deciding whether work is
Expand Down
2 changes: 2 additions & 0 deletions libs/deepagents/deepagents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from deepagents._version import __version__
from deepagents.graph import (
DEFAULT_AGENT_PROMPT,
DeepAgentState,
SystemPromptConfig,
create_deep_agent,
Expand All @@ -27,6 +28,7 @@
)

__all__ = [
"DEFAULT_AGENT_PROMPT",
"AsyncSubAgent",
"AsyncSubAgentMiddleware",
"CompiledSubAgent",
Expand Down
40 changes: 34 additions & 6 deletions libs/deepagents/deepagents/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DeepAgentState(AgentState):
messages: Required[Annotated[list[AnyMessage], DeltaChannel(_messages_delta_reducer, snapshot_frequency=50)]] # ty: ignore[invalid-argument-type]


BASE_AGENT_PROMPT = """You are a deep agent, an AI assistant that helps users accomplish tasks using tools. You respond with text and tool calls. The user can see your responses and tool outputs in real time.
DEFAULT_AGENT_PROMPT = """You are a deep agent, an AI assistant that helps users accomplish tasks using tools. You respond with text and tool calls. The user can see your responses and tool outputs in real time.

## Core Behavior

Expand Down Expand Up @@ -117,7 +117,18 @@ class DeepAgentState(AgentState):
## Progress Updates

For longer tasks, provide brief progress updates at reasonable intervals — a concise sentence recapping what you've done and what's next.""" # noqa: E501
"""Default base system prompt for every deep agent.
"""Authored base prompt (persona + task guidance), available for opt-in.

Not injected by default. `BASE_AGENT_PROMPT` — the base the prompt assembler
uses — is empty, so a deep agent ships with no authored base prompt. Callers who
want this built-in persona and task guidance back pass it explicitly, e.g.
`create_deep_agent(system_prompt={"base": DEFAULT_AGENT_PROMPT})`, or set it as a
`HarnessProfile.base_system_prompt`.
"""


BASE_AGENT_PROMPT = ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the point of this?

"""Default base system prompt for every deep agent (empty by default).

The final system prompt sent to the model is assembled, in order, from:

Expand Down Expand Up @@ -734,6 +745,19 @@ class MyState(DeepAgentState):

backend = backend if backend is not None else StateBackend()

# The built-in tool-usage guidance prose duplicates the tools' own schema
# descriptions, so it is trimmed on every stack below (main agent, subagents,
# general-purpose subagent) via each middleware's `system_prompt`:
# - `TodoListMiddleware` and `FilesystemMiddleware` always append, so `""`
# trims their prose. Filesystem's host-path routing section is preserved
# regardless (see `_filter_unsupported_tools_and_apply_prompt`).
# - subagent / async-subagent treat `None` as "no fragment", so `None`
# trims. The available-agent list still reaches the model through the
# `task` tool / async tools, so only the duplicate usage prose is dropped.
# Skills and Memory are never trimmed: their fragment is the only channel that
# surfaces the loaded skill index / memory content (no tool carries it), and
# both are built only when the caller passes `skills=` / `memory=`.

# Process caller-supplied subagents first so the decision of whether to
# auto-add the default general-purpose subagent can factor in an explicit
# override, and so its middleware stack (including any factory-based
Expand Down Expand Up @@ -761,11 +785,12 @@ class MyState(DeepAgentState):

# Build middleware: base stack + skills (if specified) + user's middleware
subagent_middleware: list[AgentMiddleware[Any, Any, Any]] = [
TodoListMiddleware(),
TodoListMiddleware(system_prompt=""),
FilesystemMiddleware(
backend=backend,
custom_tool_descriptions=_subagent_profile.tool_description_overrides,
_permissions=subagent_permissions,
system_prompt="",
),
create_summarization_middleware(subagent_model, backend),
PatchToolCallsMiddleware(),
Expand Down Expand Up @@ -847,11 +872,12 @@ class MyState(DeepAgentState):
gp_profile = _profile.general_purpose_subagent or GeneralPurposeSubagentProfile()
if gp_profile.enabled is not False and not any(spec["name"] == GENERAL_PURPOSE_SUBAGENT["name"] for spec in inline_subagents):
gp_middleware: list[AgentMiddleware[Any, Any, Any]] = [
TodoListMiddleware(),
TodoListMiddleware(system_prompt=""),
FilesystemMiddleware(
backend=backend,
custom_tool_descriptions=_profile.tool_description_overrides,
_permissions=permissions,
system_prompt="",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how do we feel about all the dead code here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we haven't already, we need to audit the content we're losing from system prompts (i.e., is not duplicated in tool descriptions) and convince ourselves we don't want them.

some things we lose:

  • behavior around large tool result eviction (I guess you can infer what happened from the tool messages?)
  • virtual mount paths for execute
  • guidance not to call todo list multiple times in parallel

),
create_summarization_middleware(model, backend),
PatchToolCallsMiddleware(),
Expand Down Expand Up @@ -913,7 +939,7 @@ class MyState(DeepAgentState):

# Build main agent middleware stack
deepagent_middleware: list[AgentMiddleware[Any, Any, Any]] = [
TodoListMiddleware(),
TodoListMiddleware(system_prompt=""),
]
if skills is not None:
deepagent_middleware.append(SkillsMiddleware(backend=backend, sources=skills))
Expand All @@ -922,6 +948,7 @@ class MyState(DeepAgentState):
backend=backend,
custom_tool_descriptions=_profile.tool_description_overrides,
_permissions=permissions,
system_prompt="",
)
)
sub_agent_middleware: SubAgentMiddleware | None = None
Expand All @@ -936,6 +963,7 @@ class MyState(DeepAgentState):
# template. Stale keys silently no-op if the tool is renamed.
task_description=_profile.tool_description_overrides.get("task"),
state_schema=state_schema,
system_prompt=None,
)
deepagent_middleware.append(sub_agent_middleware)
deepagent_middleware.extend(
Expand All @@ -948,7 +976,7 @@ class MyState(DeepAgentState):
if async_subagents:
# Async here means that we run these subagents in a non-blocking manner.
# Currently this supports agents deployed via LangSmith deployments.
deepagent_middleware.append(AsyncSubAgentMiddleware(async_subagents=async_subagents))
deepagent_middleware.append(AsyncSubAgentMiddleware(async_subagents=async_subagents, system_prompt=None))

# Names of the core stack, captured before the tail is appended so new user
# middleware can splice in ahead of the profile/prompt-caching/memory tail.
Expand Down
10 changes: 8 additions & 2 deletions libs/deepagents/deepagents/middleware/async_subagents.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,11 @@ async def acheck_async_task(
name="check_async_task",
func=check_async_task,
coroutine=acheck_async_task,
description="Check the status of an async subagent task. Returns the current status and, if complete, the result.",
description=(
"Check the status of an async subagent task. Returns the current status and, if complete, the result. "
"Statuses shown earlier in the conversation are always stale, so call this to get the current status "
"rather than reporting a status from a previous tool result."
),
infer_schema=False,
args_schema=CheckAsyncTaskSchema,
)
Expand Down Expand Up @@ -833,7 +837,9 @@ async def alist_async_tasks(
"List tracked async subagent tasks with their current live statuses. "
"By default shows all tasks. Use `status_filter` to narrow by status "
"(e.g. 'running', 'success', 'error', 'cancelled'). "
"Use `check_async_task` to get the full result of a specific completed task."
"Use `check_async_task` to get the full result of a specific completed task. "
"Statuses shown earlier in the conversation are always stale, so call this to read current "
"statuses rather than reporting one from a previous tool result."
),
infer_schema=False,
args_schema=ListAsyncTasksSchema,
Expand Down
17 changes: 15 additions & 2 deletions libs/deepagents/deepagents/middleware/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ class ExecuteSchema(BaseModel):
- Lines longer than 5,000 characters will be split into multiple lines with continuation markers (e.g., 5.1, 5.2, etc.). `limit` applies to source lines, so continuation rows do not consume the budget.
- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
- If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.
- Large tool results are sometimes offloaded to a file (under a `large_tool_results/` directory) instead of returned inline; the tool message gives the path. Read that file here, using `offset`/`limit` to page through it.
- Image files (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, etc.), audio and video files, and PDFs are returned as multimodal content blocks (see https://docs.langchain.com/oss/python/langchain/messages#multimodal).

For multimodal reads (image, audio, video, PDF, etc.):
Expand Down Expand Up @@ -1043,6 +1044,9 @@ class ExecuteSchema(BaseModel):
`|` alternation: `grep(pattern="foo|bar")` looks for the literal text "foo|bar".
- Do not use wildcards (`.*`) or escapes (`\\.`); they match those characters literally.{execute_fallback}

To search across offloaded large tool results when you do not know the exact
file path, grep the `large_tool_results/` directory.
Comment thread
robin-agent[bot] marked this conversation as resolved.
Resolved

Examples:
- Search all files: `grep(pattern="TODO")`
- Search Python files only: `grep(pattern="import", glob="*.py")`
Expand Down Expand Up @@ -2792,9 +2796,18 @@ def _filter_unsupported_tools_and_apply_prompt(self, request: ModelRequest[Conte
if described_tools is not visible_tools:
request = request.override(tools=described_tools)

# Use custom system prompt if provided, otherwise generate dynamically
# A `system_prompt` override (including `""` suppression) replaces only the
# usage-guidance prose. The host-path routing section is essential
# per-backend config (virtual->host path mapping for the `execute` shell),
# not prose, so it is still appended when the execute tool is active — even
# when the prose is overridden or suppressed.
if self._custom_system_prompt is not None:
system_prompt = self._custom_system_prompt
prompt_parts = [self._custom_system_prompt] if self._custom_system_prompt else []
if execution_active:
route_prompt = _route_host_path_prompt(cast("BackendProtocol", backend))
if route_prompt:
prompt_parts.append(route_prompt)
system_prompt = "\n\n".join(prompt_parts).strip()
else:
# Build dynamic system prompt reflecting only the tools that survived filtering
visible_fs = {n for n in (tool_names - unsupported) if n is not None}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from deepagents.backends import CompositeBackend, StateBackend, StoreBackend
from deepagents.middleware.filesystem import (
EXECUTION_SYSTEM_PROMPT,
GREP_TOOL_DESCRIPTION,
READ_FILE_TOOL_DESCRIPTION,
WRITE_FILE_TOOL_DESCRIPTION,
FilesystemMiddleware,
)
Expand All @@ -21,6 +23,21 @@ def build_composite_state_backend(*, routes: dict[str, Any]) -> CompositeBackend
return CompositeBackend(default=StateBackend(), routes=routes)


class TestLargeToolResultGuidanceInToolDescriptions:
"""Large-tool-result offload guidance lives in the tool descriptions.

It used to be in the (now-trimmed) filesystem system prompt, so it is
migrated into the always-visible `read_file` / `grep` descriptions.
"""

def test_read_file_describes_offloaded_results(self) -> None:
assert "large_tool_results/" in READ_FILE_TOOL_DESCRIPTION
assert "offloaded" in READ_FILE_TOOL_DESCRIPTION.lower()

def test_grep_describes_searching_offloaded_results(self) -> None:
assert "large_tool_results/" in GREP_TOOL_DESCRIPTION


class TestDynamicSystemPromptCache:
"""`_build_dynamic_system_prompt` caches per `include_execution` flag."""

Expand Down
Loading