Add protocol prompt area before history
Some checks are pending
Build And Publish Docker Images / plan (push) Waiting to run
Build And Publish Docker Images / build (push) Blocked by required conditions

Introduce a new prompt "protocol" separate from extras: add LoopData.protocol_temporary and protocol_persistent, include protocol contents before message history during prompt construction, and clear temporary protocol data each turn. Add helper _build_context_message to render protocol/extras, update response input conversion to include protocol, and move project instructions & active/loaded skills injection into protocol. Update docs, prompts, plugin metadata, the SkillsTool message, and add tests to verify protocol placement and behavior.
This commit is contained in:
frdel 2026-06-18 21:42:06 +02:00
parent bf2741990a
commit afdc3aeb44
24 changed files with 236 additions and 53 deletions

View file

@ -44,7 +44,7 @@ Direct child DOX files:
| [hist_add_tool_result/AGENTS.md](hist_add_tool_result/AGENTS.md) | Tool-result history side effects. |
| [job_loop/AGENTS.md](job_loop/AGENTS.md) | Periodic backend maintenance jobs. |
| [message_loop_end/AGENTS.md](message_loop_end/AGENTS.md) | End-of-message-loop history and persistence behavior. |
| [message_loop_prompts_after/AGENTS.md](message_loop_prompts_after/AGENTS.md) | Prompt extras appended after message-loop prompt construction. |
| [message_loop_prompts_after/AGENTS.md](message_loop_prompts_after/AGENTS.md) | Prompt protocol and extras assembled around message-loop prompt construction. |
| [message_loop_prompts_before/AGENTS.md](message_loop_prompts_before/AGENTS.md) | Pre-prompt-construction message-loop gates. |
| [message_loop_start/AGENTS.md](message_loop_start/AGENTS.md) | Start-of-message-loop iteration state. |
| [monologue_end/AGENTS.md](monologue_end/AGENTS.md) | End-of-monologue UI and cleanup behavior. |

View file

@ -2,11 +2,12 @@
## Purpose
- Own prompt extras appended after primary message-loop prompt construction.
- Own prompt protocol and extras appended around primary message-loop prompt construction.
## Ownership
- Ordered Python files own current datetime, skill recall/load context, agent info, parallel job status, and workdir extras injection.
- Loaded and active skill instructions belong in prompt protocol, not prompt extras.
## Local Contracts
@ -16,11 +17,11 @@
## Work Guidance
- Coordinate prompt-extra changes with skill, workdir, and profile contracts.
- Coordinate prompt protocol and prompt-extra changes with skill, workdir, and profile contracts.
## Verification
- Inspect rendered prompt extras or run prompt-construction tests after changes.
- Inspect rendered prompt protocol/extras or run prompt-construction tests after changes.
## Child DOX Index

View file

@ -9,7 +9,8 @@ class IncludeLoadedSkills(Extension):
if not self.agent:
return
extras = loop_data.extras_persistent
protocol = loop_data.protocol_persistent
protocol.pop("loaded_skills", None)
# Get loaded skills names
skill_names = self.agent.data.get(DATA_NAME_LOADED_SKILLS)
@ -31,8 +32,8 @@ class IncludeLoadedSkills(Extension):
return
# Inject into extras
extras["loaded_skills"] = self.agent.read_prompt(
# Inject into protocol
protocol["loaded_skills"] = self.agent.read_prompt(
"agent.system.skills.loaded.md",
skills=content,
)

View file

@ -7,6 +7,7 @@
## Ownership
- Ordered Python files own main, tools, MCP, secrets, skills, and project prompt sections.
- Active project instruction bodies are moved into prompt protocol; the system prompt keeps project metadata and stable project rules.
## Local Contracts

View file

@ -15,17 +15,24 @@ class ProjectPrompt(Extension):
):
if not self.agent:
return
prompt = await build_prompt(self.agent)
prompt = await build_prompt(self.agent, loop_data=loop_data)
if prompt:
system_prompt.append(prompt)
@extensible
async def build_prompt(agent: Agent) -> str:
async def build_prompt(agent: Agent, loop_data: LoopData | None = None) -> str:
result = agent.read_prompt("agent.system.projects.main.md")
project_name = agent.context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)
if loop_data:
loop_data.protocol_persistent.pop("project_instructions", None)
if project_name:
project_vars = projects.build_system_prompt_vars(project_name)
if loop_data and project_vars.get("project_instructions"):
loop_data.protocol_persistent["project_instructions"] = agent.read_prompt(
"agent.protocol.projects.instructions.md",
**project_vars,
)
result += "\n\n" + agent.read_prompt(
"agent.system.projects.active.md", **project_vars
)