Skip to content

feat(coding-agent): include custom tools in system prompt#1237

Open
semtexzv wants to merge 2 commits intobadlogic:mainfrom
semtexzv:feat/custom-tool-system-prompt
Open

feat(coding-agent): include custom tools in system prompt#1237
semtexzv wants to merge 2 commits intobadlogic:mainfrom
semtexzv:feat/custom-tool-system-prompt

Conversation

@semtexzv
Copy link

@semtexzv semtexzv commented Feb 3, 2026

Custom tools registered via extensions or the SDK are available to the LLM through the API tool listing, but invisible in the system prompt. The "Available tools" and "Guidelines" sections only show built-ins. This means the LLM gets no high-level orientation about custom tools and extension authors can't inject behavioral guidelines.

Changes

Add two optional fields to ToolDefinition:

  • shortDescription — one-liner for the system prompt tool list (falls back to first line of description)
  • systemGuidelines — bullet points appended to the system prompt guidelines section

Custom tools now appear in the system prompt alongside built-ins, with stable ordering: built-ins first (fixed order), then custom tools alphabetically. Guidelines are deduplicated via Set.

Example:

pi.registerTool({
  name: "my_tool",
  description: "Manage a todo list. Supports listing, adding, and removing items.",
  shortDescription: "Manage a todo list",
  systemGuidelines: ["Confirm with the user before removing todo items"],
  // ...
});

Produces:

Available tools:
- read: Read file contents
- bash: Execute bash commands (ls, grep, find, etc.)
- my_tool: Manage a todo list

Guidelines:
- Use read to examine files before editing...
- Confirm with the user before removing todo items

Files

  • extensions/types.ts — add shortDescription?, systemGuidelines? to ToolDefinition
  • system-prompt.tsSystemPromptToolInfo, resolveShortDescription() fallback, addGuideline() dedup, export DEFAULT_TOOL_ORDER
  • agent-session.ts — build SystemPromptToolInfo map from built-in + custom tools, stable ordering, pass tools to buildSystemPrompt()
  • docs/extensions.md — document new fields with examples
  • docs/sdk.md — document new fields for SDK usage

Possible follow-up: Per-tool system prompt sections

This is out of scope for this PR but worth considering:

  • a systemPromptSection field that emits a dedicated block per tool in the system prompt, similar to how skills get <available_skills> and context files get ## path sections.
  • This would allow extensions to provide usage examples, workflow descriptions, or domain context beyond what fits in a guideline bullet. Could be placed before the skills listing:

@badlogic
Copy link
Owner

badlogic commented Feb 4, 2026

Default behavior change: buildSystemPrompt currently defaults to read/bash/edit/write when callers pass no tools. This PR makes the implicit default all built-ins via DEFAULT_TOOL_ORDER. Please keep the default at read/bash/edit/write for direct buildSystemPrompt callers.

@semtexzv semtexzv force-pushed the feat/custom-tool-system-prompt branch 10 times, most recently from b23e76e to 8d2a911 Compare February 4, 2026 10:07
…escription and systemGuidelines

- Include custom tools in the system prompt tool list alongside built-in tools
- Add shortDescription field for concise system prompt entries (falls back to first line of description)
- Add systemGuidelines field for tool-specific guideline bullets
- Stable tool ordering: built-ins first (fixed order), then custom tools alphabetically
- Deduplicate guidelines via Set
- Update extensions.md and sdk.md docs
@semtexzv semtexzv force-pushed the feat/custom-tool-system-prompt branch from 8d2a911 to 62a7be3 Compare February 4, 2026 10:09
@semtexzv
Copy link
Author

semtexzv commented Feb 4, 2026

Updated the behavior to keep the previous system prompt for existing callers.

Additionally:

  1. Added a way to exclude tool from system prompt, if shortDescription is "", tool is excluded.
  2. Added tests to cover different behaviors.

@badlogic
Copy link
Owner

badlogic commented Feb 4, 2026

Signaling exclusion via empty string is not great. I think it should be opt in: if shortDescription is givren, include, otherwise don't, guidelines optional.

…iption

Custom tools only appear in the system prompt 'Available tools' section
when shortDescription is explicitly provided. Previously, omitting it
fell back to the first line of description, and empty string was used
to signal exclusion.

Now: provided = shown, omitted = hidden. Guidelines still work
regardless of visibility.
@semtexzv
Copy link
Author

semtexzv commented Feb 4, 2026

Updated. Kept it as a separate commit, will rebase for submission

@semtexzv semtexzv force-pushed the feat/custom-tool-system-prompt branch from a7284c1 to be92c79 Compare February 4, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants