Repository navigation
feat(sdk,code,quickjs): lean system prompt by default, restorable #4859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e154953
ce23402
8d71dde
404d8f0
3ac886f
a08b327
36a22cd
40880b3
688d82c
cb90572
fb9c3d1
5b50172
1ab4c4a
c9dbda2
4d825bb
5d222b1
c3c0ad0
90ab0c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -117,16 +117,29 @@ 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 = "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
||
| 1. `prefix` — caller text placed before the base (the `system_prompt=` | ||
| argument, or its `prefix` key). Always first, so caller instructions | ||
| take precedence. | ||
| 2. `base` — this constant by default; replaced by the `system_prompt` | ||
| 2. `base` — this constant by default (empty); replaced by the `system_prompt` | ||
| config's `base` key, or (when that key is absent) by | ||
| `HarnessProfile.base_system_prompt`. Setting `base` to `None` drops it. | ||
| Pass [`DEFAULT_AGENT_PROMPT`][deepagents.DEFAULT_AGENT_PROMPT] as the `base` | ||
| to restore the built-in authored prompt. | ||
| 3. `suffix` — caller text placed after the base (the `system_prompt` | ||
| config's `suffix` key). | ||
| 4. `HarnessProfile.system_prompt_suffix` — model-tuning guidance appended | ||
|
|
@@ -378,6 +391,7 @@ def create_deep_agent( # noqa: C901, PLR0912, PLR0915 # Complex graph assembly | |
| tools: Sequence[BaseTool | Callable | dict[str, Any]] | None = None, | ||
| *, | ||
| system_prompt: str | SystemMessage | SystemPromptConfig | None = None, | ||
| trim_duplicate_tool_prompts: bool = True, | ||
| middleware: Sequence[AgentMiddleware[StateT_co, ContextT]] = (), | ||
| subagents: Sequence[SubAgent | CompiledSubAgent | AsyncSubAgent] | None = None, | ||
| skills: list[str] | None = None, | ||
|
|
@@ -449,22 +463,38 @@ def create_deep_agent( # noqa: C901, PLR0912, PLR0915 # Complex graph assembly | |
| system_prompt: Custom system instructions. | ||
|
|
||
| A `str` or `SystemMessage` is placed at the front of the system | ||
| prompt, before the SDK's default base prompt and any model-tuning | ||
| suffix from a registered `HarnessProfile` (`system_prompt=None` | ||
| uses the default base on its own). | ||
| prompt, before the base prompt (empty by default) and any | ||
| model-tuning suffix from a registered `HarnessProfile`. | ||
|
|
||
| For more control, pass a | ||
| [`SystemPromptConfig`][deepagents.SystemPromptConfig] with any of: | ||
|
|
||
| - `prefix`: text before the base (same as passing a bare string). | ||
| - `base`: replace the built-in base prompt; omit the key to keep | ||
| it, or set it to `None` to drop the base entirely. | ||
| - `base`: replace the base prompt; omit the key to keep the default | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we intend to drop the system_prompt configurability that was added earlier in the 0.7 alpha period. I appreciate keeping things consistent but this will just add merge conflicts when we revert. |
||
| (empty), or set it to `None` to drop the base entirely. Pass | ||
| [`DEFAULT_AGENT_PROMPT`][deepagents.DEFAULT_AGENT_PROMPT] to | ||
| restore the built-in authored prompt. | ||
| - `suffix`: text after the base (before any profile suffix). | ||
|
|
||
| The assembly order is `prefix` -> `base` -> `suffix` -> | ||
| profile suffix, joined by blank lines. Any part may be a | ||
| `SystemMessage` to preserve `cache_control` markers; the result is | ||
| then a `SystemMessage` whose content blocks are concatenated. | ||
| trim_duplicate_tool_prompts: Whether to drop the built-in tool-usage | ||
| guidance prose that largely duplicates the tools' own descriptions. | ||
|
|
||
| `True` (default): the todo, filesystem, and subagent middleware are | ||
| built without their usage-guidance prose, on every stack (main agent, | ||
| subagents, and the general-purpose subagent). The tools and their own | ||
| schema descriptions are unaffected, so the model still knows how to | ||
| call them; only the redundant prose is trimmed. Set this to `False` | ||
| to keep the full built-in guidance. | ||
|
|
||
| This is deliberately narrow. It only trims prose that repeats the | ||
| tool schemas. It never touches content that the schemas do not carry: | ||
| the skills index and memory content (emitted whenever `skills=` / | ||
| `memory=` are set) and the filesystem host-path routing section | ||
| always remain, regardless of this flag. | ||
| middleware: Additional middleware to apply after the base stack | ||
| but before the tail middleware. The full ordering is: | ||
|
|
||
|
|
@@ -734,6 +764,30 @@ class MyState(DeepAgentState): | |
|
|
||
| backend = backend if backend is not None else StateBackend() | ||
|
|
||
| # Trim the built-in tool-usage guidance prose that duplicates the tool | ||
| # schemas. When `trim_duplicate_tool_prompts` (the default), todo / | ||
| # filesystem / subagent / async-subagent are constructed with that prose | ||
| # dropped, on every stack below (main agent, subagents, general-purpose | ||
| # subagent). The trim value depends on how the middleware treats | ||
| # `system_prompt`: | ||
| # - `TodoListMiddleware` always appends, so `""` trims; omitting the kwarg | ||
| # (empty dict) keeps its built-in prose. | ||
| # - `FilesystemMiddleware` builds its prose when `system_prompt is None`, | ||
| # so it is passed explicitly at each call site (`""` to trim, `None` to | ||
| # keep). Its host-path routing section is preserved either way (see | ||
| # `_filter_unsupported_tools_and_apply_prompt`). | ||
| # - subagent / async-subagent treat `None` as "no fragment", so `None` | ||
| # trims; omitting the kwarg keeps it. 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 intentionally 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 explicitly passes | ||
| # `skills=` / `memory=`. Trimming them would silently disable an opted-into | ||
| # feature, so they always emit their built-in fragment. | ||
| _empty_prompt_kwargs: dict[str, str] = {"system_prompt": ""} if trim_duplicate_tool_prompts else {} | ||
| _none_prompt_kwargs: dict[str, None] = {"system_prompt": None} if trim_duplicate_tool_prompts else {} | ||
|
|
||
| # 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 | ||
|
|
@@ -761,11 +815,12 @@ class MyState(DeepAgentState): | |
|
|
||
| # Build middleware: base stack + skills (if specified) + user's middleware | ||
| subagent_middleware: list[AgentMiddleware[Any, Any, Any]] = [ | ||
| TodoListMiddleware(), | ||
| TodoListMiddleware(**_empty_prompt_kwargs), | ||
| FilesystemMiddleware( | ||
| backend=backend, | ||
| custom_tool_descriptions=_subagent_profile.tool_description_overrides, | ||
| _permissions=subagent_permissions, | ||
| system_prompt="" if trim_duplicate_tool_prompts else None, | ||
| ), | ||
| create_summarization_middleware(subagent_model, backend), | ||
| PatchToolCallsMiddleware(), | ||
|
|
@@ -847,11 +902,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(**_empty_prompt_kwargs), | ||
| FilesystemMiddleware( | ||
| backend=backend, | ||
| custom_tool_descriptions=_profile.tool_description_overrides, | ||
| _permissions=permissions, | ||
| system_prompt="" if trim_duplicate_tool_prompts else None, | ||
| ), | ||
| create_summarization_middleware(model, backend), | ||
| PatchToolCallsMiddleware(), | ||
|
|
@@ -913,7 +969,7 @@ class MyState(DeepAgentState): | |
|
|
||
| # Build main agent middleware stack | ||
| deepagent_middleware: list[AgentMiddleware[Any, Any, Any]] = [ | ||
| TodoListMiddleware(), | ||
| TodoListMiddleware(**_empty_prompt_kwargs), | ||
| ] | ||
| if skills is not None: | ||
| deepagent_middleware.append(SkillsMiddleware(backend=backend, sources=skills)) | ||
|
|
@@ -922,6 +978,7 @@ class MyState(DeepAgentState): | |
| backend=backend, | ||
| custom_tool_descriptions=_profile.tool_description_overrides, | ||
| _permissions=permissions, | ||
| system_prompt="" if trim_duplicate_tool_prompts else None, | ||
| ) | ||
| ) | ||
| sub_agent_middleware: SubAgentMiddleware | None = None | ||
|
|
@@ -936,6 +993,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, | ||
| **_none_prompt_kwargs, | ||
| ) | ||
| deepagent_middleware.append(sub_agent_middleware) | ||
| deepagent_middleware.extend( | ||
|
|
@@ -948,7 +1006,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, **_none_prompt_kwargs)) | ||
|
|
||
| # 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. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should leave this configurable. who would ever want this to be False? IMO we change the prompts in 0.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok what if someone really wants it back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed for now