Flows category icon
Harness Engineering
Advanced

Assemble Tool Prompts Dynamically per Environment

Stop shipping one static mega-prompt: generate tool prompts from environment conditions, inject blocks only when features are on, and dedupe config to save tokens.

4 steps12 verify checks90-120 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/4 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
My agent has one hardcoded system/tool prompt that describes features that are sometimes disabled, wasting tokens and confusing the model. Claude Code generates its BashTool prompt per environment: sandbox rules appear only when sandboxing is on, git protocols only when relevant, and config lists are deduped before injection.

GOAL:
Replace static tool prompts with a generator that assembles blocks conditionally from the live environment and measures the token cost of every block.

REQUIREMENTS:
- A prompt generator function per tool, not a static string
- Feature-gated blocks: sandbox, background tasks, git protocols included only when active
- Live config (allowed paths, hosts, limits) injected from the source of truth, deduped
- A token count logged per assembled prompt so drift is visible
- Different variants for different user classes where workflows differ

CONSTRAINTS:
- The generator must be deterministic for a given environment - same inputs, same bytes
- Never describe a capability the current environment has disabled

DEFINITION OF DONE:
- Toggling a feature flag visibly adds/removes its prompt block
- Injected config matches the enforcing code's actual values
- Token counts per block are logged and reviewed
- No prompt text references a disabled capability

COMMON FAILURES TO AVOID:
- A static prompt describing sandbox rules while sandboxing is off, teaching the model false constraints
- Config duplicated from multiple sources bloating every request by hundreds of tokens
- Prompt and enforcement drifting apart because values are hand-copied
- No measurement, so prompt bloat accumulates invisibly

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More Harness Engineering flows that share ground with this one.

Flows category icon
Harness Engineering

Design Layered Tool Prompts with Preference Chains

Structure your tool prompts the way the leading harness does: preference chains up front, usage constraints in the middle, NEVER-guarded safety protocols at the end.

01Audit the current tool prompt
02Write the preference chain
03Write usage constraints and safety protocols

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate
Flows category icon
Harness Engineering

Pair Every Prompt Rule with a Code Backstop

Prompts guide, code enforces: inventory your agent's soft rules, back each critical one with an independent deterministic check, and define the allow/ask/deny escalation.

01Inventory soft rules and classify enforcement needs
02Implement checks independent of the prompt
03Wire the escalation path

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps120-180 minutesAdvanced
Flows category icon
Harness Engineering

Verification Loops: Never Trust an Unrun Edit

Wire verification into your agent so every edit is checked by machines - syntax, tests, behavior - before it counts as done.

01Verify at the write boundary
02Add the post-change verify step
03Gate completion on evidence

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-100 minutesIntermediate

Made with Emergent