Task 8 — Default System Prompt: Chunked-Artifact Guidance
Directs an LLM agent to split long artifact outputs into multiple tool calls to avoid inference timeouts.
What this file does
Directs an LLM agent to split long artifact outputs into multiple tool calls to avoid inference timeouts.
When to use it
- Adding chunking guidance to a system prompt for agents that produce large artifacts
- Implementing a conditional prompt modifier gated on tool availability
- Writing tests that verify prompt content based on agent configuration
Assumes this stack
Task 8 — Default System Prompt: Chunked-Artifact Guidance
Agent Instructions
You are a software engineer implementing one module of a larger system. Your scope is strictly limited to this task.
CRITICAL PRE-WORK: Before beginning implementation, you MUST read:
docs/exec-plans/active/agent-capabilities/llm-transport-hardening/plan.md— overall architecture.- Issue #85 — root cause for the worst-case generation: model packs a 7k-token report into one
create_text_artifacttool argument. - The default system prompt assembly in the worker (locate via
grep -rn "create_text_artifact" services/worker-service/). The exact file is likelyservices/worker-service/executor/system_prompts.pyor assembled insideexecutor/graph.pynear the agent_node setup. Find the canonical site before editing. services/worker-service/executor/tools/...for thecreate_text_artifacttool definition — confirm whether the tool supports incremental writes (append mode, multiple calls with the same artifact name, etc.) or whether the prompt guidance must direct the agent to split logically across separately-named artifacts.
CRITICAL POST-WORK: After completing this task:
- Run
services/worker-service/.venv/bin/python -m pytest services/worker-service/tests/test_system_prompts.py -v(locate or create this test file). - Update
progress.mdrow 8 to "Done".
Context
The pathological case from #85 — a 7k-token tool-use block emitted in a single shot — is the dominant cause of the timeout-class failure. Even with streaming + maxTokens caps, the agent producing such a giant tool argument is the root behavioral pattern. Steering the model to write incrementally is the single highest-leverage prompt-side fix.
The guidance is conditional on create_text_artifact (or whatever the artifact tool's registered name is) being present in the agent's allowed tools. Agents without artifact tools should not see irrelevant guidance.
Task-Specific Shared Contract
- Guidance is appended to (not replacing) the existing system prompt assembled per-agent.
- Guidance is gated on the artifact tool being in
agent_config.allowed_tools(or however the runtime detects available tools — locate the actual check). - Wording is direct and concrete: tells the agent that long deliverables (>1500 words / >2000 tokens) should be split into multiple
create_text_artifactcalls, with section headers indicating the role of each artifact ("part 1: introduction", "part 2: features A-D", etc.). It is not a soft suggestion; treat it as a directive. - A short rationale is included so the agent understands the constraint isn't arbitrary: "Generating a single very large tool argument can exceed inference timeouts. Split long outputs into multiple artifacts."
- Wording is reviewed by the orchestrator before merge — propose 2 wording variants in the PR description and let the reviewer pick.
Affected Component
- Service/Module: Worker — Executor (system prompt assembly)
- File paths:
services/worker-service/executor/system_prompts.py(modify — or wherever the per-agent system prompt is assembled)services/worker-service/tests/test_system_prompts.py(new or extend)
- Change type: modification + new tests
Dependencies
- Must complete first: None.
- Provides output to: Task 9 (acceptance criteria asserts the guidance is present in the prompt for the repro task's agent).
- Shared interfaces/contracts: none — the change is internal to the system-prompt assembly path.
Implementation Specification
Locate the assembly site
Use the codebase's existing system-prompt builder (likely assemble_system_prompt(agent_config) -> str or similar). If no single function exists, refactor lightly to introduce one — keep the diff small and focused on this concern.
Add the conditional guidance
When the agent's allowed tools contain the artifact tool's name, append a new paragraph (kept under 6 sentences, ~120 words) covering:
- The threshold for chunking (≥ 1500 words / ≥ 2000 tokens of intended output).
- The instruction: emit multiple
create_text_artifactcalls with descriptive section names. - Short rationale (one sentence).
- Optional pattern hint: "If the deliverable has natural sections, name artifacts by section. Otherwise number them: report-part-1, report-part-2."
Tests
In tests/test_system_prompts.py:
- Agent config with
allowed_toolscontainingcreate_text_artifact: assembled prompt contains a substring matching the chunking guidance (assert against a stable phrase, not the full text — wording may be tuned). - Agent config without
create_text_artifact: assembled prompt does not contain the chunking guidance. - Agent config with
create_text_artifactplus other tools: chunking guidance appears exactly once. - The chunking guidance does not duplicate any existing prompt text (avoid running through repeats on prompt re-assembly).
Acceptance Criteria
- System prompts for agents with the artifact tool include explicit chunking guidance.
- System prompts for agents without the artifact tool are unchanged.
- Tests above pass.
- Two wording variants proposed in the PR description for orchestrator review.
Out of Scope
- Modifying the
create_text_artifacttool itself to enforce a per-call size limit. - Adding "chunked artifact" affordance to other tools.
- A/B testing the prompt against the pre-change baseline (would be valuable but is a follow-up project).
What's inside
Task specification with 8 sections: instructions, context, contract, affected files, dependencies, implementation, acceptance criteria, out-of-scope
Change this for your project
- Replace
shenjianan97/persistent-agent-runtimewith your repository name - Replace
services/worker-service/with your service path - Replace
create_text_artifactwith your artifact tool's registered name - Replace
docs/exec-plans/active/agent-capabilities/llm-transport-hardening/plan.mdwith your architecture doc path
Where it goes
Use as the system prompt for your model call, or as the base instructions in your agent framework.
Worth borrowing
- Gate prompt additions on the presence of a specific tool in the agent's allowed tools list
- Propose two wording variants in the PR description for reviewer selection
Related Documents
Character Persona
Defines a Fallout 2 roleplay persona for an LLM agent: charming rogue with social-first combat and moral code.
How to implement tool use
Explains how to define, configure, and control tool use with the Anthropic API, including model selection, tool definitions, output control, and parallel calls.
Gemini by Example
Collects 20+ Gemini API code examples covering text, images, audio, video, PDFs, agents, and token counting.
Claude Tool Use (Function Calling) Documentation
Teaches how to define and use Claude tool use (function calling) with Python, including schema rules, execution patterns, and best practices.