core/config: split agent system_prompt and tool_directives

This commit is contained in:
2026-07-21 22:55:51 +08:00
parent db7c097466
commit 30beec6600
8 changed files with 132 additions and 16 deletions
+3 -2
View File
@@ -29,8 +29,9 @@ _MINIMAL_CONFIG = """\
# # url = ":memory:"
# [agent]
# # system_prompt defaults to the built-in coding-agent guide when omitted.
# # system_prompt = "" # disable; or multi-line '''...''' to override
# # system_prompt = persona (omit → built-in). tool_directives = tool playbook.
# # system_prompt = "" / tool_directives = "" disable each part; both "" → no system.
# # Or multi-line '''...''' to override.
# max_tool_result_chars = 32000
# parallel_tools = true
# confirm_destructive = true
+5 -1
View File
@@ -169,9 +169,13 @@ class ReplState:
def _make_agent(self) -> ChatAgent:
from plyngent.cli.limits import prompt_continue_limit_async
from plyngent.config import compose_agent_system_content
agent_cfg = self.config.agent_config
system_prompt = agent_cfg.system_prompt or None
system_prompt = compose_agent_system_content(
agent_cfg.system_prompt,
agent_cfg.tool_directives,
)
on_limit = prompt_continue_limit_async if self.interactive_limits else None
return ChatAgent(
self.client,
+2
View File
@@ -6,6 +6,7 @@ import tomlkit
from tomlkit.exceptions import TOMLKitError
from .models import DEFAULT_SYSTEM_PROMPT as DEFAULT_SYSTEM_PROMPT
from .models import DEFAULT_TOOL_DIRECTIVES as DEFAULT_TOOL_DIRECTIVES
from .models import AgentConfig as AgentConfig
from .models import AnthropicProvider as AnthropicProvider
from .models import DatabaseConfig as DatabaseConfig
@@ -15,6 +16,7 @@ from .models import ModelConfig as ModelConfig
from .models import OpenAICompatibleProvider as OpenAICompatibleProvider
from .models import OpenAIProvider as OpenAIProvider
from .models import ProviderConfig as ProviderConfig
from .models import compose_agent_system_content as compose_agent_system_content
from .path import get_default_path as _get_default_path
from .store import ConfigFormatError as ConfigFormatError
from .store import ConfigStore as ConfigStore
+25 -3
View File
@@ -2,12 +2,16 @@ from typing import Any
from msgspec import Struct, field
# Built-in agent system prompt when ``[agent].system_prompt`` is omitted.
# Set ``system_prompt = ""`` in TOML to disable. Override with a multi-line
# TOML literal (prefer '''...''' so nested " quotes are fine).
# Built-in persona when ``[agent].system_prompt`` is omitted.
# Set ``system_prompt = ""`` to omit the persona block only.
# Override with a multi-line TOML literal (prefer ''' so nested " is fine).
DEFAULT_SYSTEM_PROMPT = """\
You are a professional coding agent in a workspace-bound tool environment.
"""
# Built-in tool playbook when ``[agent].tool_directives`` is omitted.
# Set ``tool_directives = ""`` to omit this block only.
DEFAULT_TOOL_DIRECTIVES = """\
### Workspace
- Explore with `tree`/`listdir`/`glob_paths`/`grep_files`/`read_file` when unsure.
- Stay under the workspace (or a path from `new_temporary_workspace`). Respect path denylists.
@@ -41,6 +45,21 @@ pop the group). Open items mean unfinished work.
"""
def compose_agent_system_content(
system_prompt: str,
tool_directives: str,
) -> str | None:
"""Join persona + tool playbook into one system body, or ``None`` if both empty.
Non-empty parts are stripped and joined with a blank line. Either field may
be ``""`` to disable that part while keeping the other.
"""
parts = [part.strip() for part in (system_prompt, tool_directives) if part and part.strip()]
if not parts:
return None
return "\n\n".join(parts)
class DatabaseConfig(Struct, omit_defaults=True):
"""Database connection configuration.
@@ -58,7 +77,10 @@ class DatabaseConfig(Struct, omit_defaults=True):
class AgentConfig(Struct, omit_defaults=True):
"""Single-user agent profile defaults."""
# Persona / role (omit → DEFAULT_SYSTEM_PROMPT; "" disables persona only).
system_prompt: str = DEFAULT_SYSTEM_PROMPT
# Tool how-to (omit → DEFAULT_TOOL_DIRECTIVES; "" disables playbook only).
tool_directives: str = DEFAULT_TOOL_DIRECTIVES
max_tool_result_chars: int = 32_000
parallel_tools: bool = True
confirm_destructive: bool = True