Engineering · AI Agent Architecture

System Prompts and Context Injection for Agents

Layered system instructions, selective tool injection, and anti-jailbreak patterns that keep prompts lean.

1. Layered prompt structure

Fixed layer: role, boundaries, output shape. Dynamic layer: retrieval, tools, session summary. Keep the fixed layer first and cache-friendly; mark dynamic data as untrusted.

2. Selective tool and example injection

Do not dump every tool schema. Supervisors inject an intent subset. Few-shots stay neutral—never embed secret workflows.

3. Injection resistance and priority

Wrap user text in delimiters; raise alerts on ignore-previous-instructions patterns. Priority is fixed: safety policy > format > user task.

4. Engineering checklist

5. Sample configuration

prompt_layers:
  - id: core_policy
    cache: true
  - id: session_context
    trust: untrusted_user_data

6. FAQ

Can retrieved text override the system prompt?
Use clear delimiters plus a lightweight pre-filter before the model.