From bbdc3503942877b435b33f913de5406030cc7b09 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sun, 28 Dec 2025 14:31:26 +0100 Subject: [PATCH] Add reference to #330 (Dynamic Context Pruning) in plan Documents why context event was added and notes the type inconsistency between ContextEvent (AgentMessage[]) and ContextEventResult (Message[]) --- .../coding-agent/docs/session-tree-plan.md | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/coding-agent/docs/session-tree-plan.md b/packages/coding-agent/docs/session-tree-plan.md index 650d0c51..ad4f6c60 100644 --- a/packages/coding-agent/docs/session-tree-plan.md +++ b/packages/coding-agent/docs/session-tree-plan.md @@ -287,19 +287,32 @@ Benefits: ### Investigate: `context` event vs `before_agent_start` -Reference: [#324](https://github.com/badlogic/pi-mono/issues/324) +References: +- [#324](https://github.com/badlogic/pi-mono/issues/324) - `before_agent_start` proposal +- [#330](https://github.com/badlogic/pi-mono/discussions/330) - Dynamic Context Pruning (why `context` was added) **Current `context` event:** - Fires before each LLM call within the agent loop - Receives `AgentMessage[]` (deep copy, safe to modify) +- Returns `Message[]` (inconsistent with input type) - Modifications are transient (not persisted to session) - No TUI visibility of what was changed - Use case: non-destructive pruning, dynamic context manipulation -**Problem:** `AgentMessage` includes custom types (hookMessage, bashExecution, etc.) that need conversion to LLM `Message[]` before sending. Need to verify: -- [ ] Where does `AgentMessage[]` → `Message[]` conversion happen relative to `context` event? -- [ ] Should hooks work with `AgentMessage[]` or `Message[]`? -- [ ] Is the current abstraction level correct? +**Type inconsistency:** Event receives `AgentMessage[]` but result returns `Message[]`: +```typescript +interface ContextEvent { + messages: AgentMessage[]; // Input +} +interface ContextEventResult { + messages?: Message[]; // Output - different type! +} +``` + +Questions: +- [ ] Should input/output both be `Message[]` (LLM format)? +- [ ] Or both be `AgentMessage[]` with conversion happening after? +- [ ] Where does `AgentMessage[]` → `Message[]` conversion currently happen? **Proposed `before_agent_start` event:** - Fires once when user submits a prompt, before `agent_start`