Wire context event to preprocessor for per-LLM-call execution

- Change from contextTransform (runs once at agent start) to preprocessor
- preprocessor runs before EACH LLM call inside the agent loop
- ContextEvent now uses Message[] (pi-ai format) instead of AppMessage[]
- Deep copy handled by pi-ai preprocessor, not Agent

This enables:
- Pruning rules applied on every turn (not just agent start)
- /prune during long agent loop takes effect immediately
- Compaction can use same transforms (future work)
This commit is contained in:
Mario Zechner 2025-12-27 19:57:14 +01:00
parent 77fe3f1a13
commit a2515cf43f
6 changed files with 22 additions and 28 deletions

View file

@ -589,7 +589,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
tools: allToolsArray,
},
messageTransformer,
contextTransform: hookRunner
preprocessor: hookRunner
? async (messages) => {
return hookRunner.emitContext(messages);
}