fix(coding-agent): add settled agent lifecycle event

closes #6363
This commit is contained in:
Mario Zechner
2026-07-09 12:40:52 +02:00
parent 050b8176bf
commit e9fa5a68a1
14 changed files with 272 additions and 32 deletions
+11 -6
View File
@@ -307,7 +307,8 @@ user sends prompt ────────────────────
│ │ │ │
│ └─► turn_end │ │
│ │
─► agent_end │
─► agent_end │
└─► agent_settled (no retry/compaction/follow-up left) │
user sends another prompt ◄────────────────────────────────┘
@@ -546,15 +547,19 @@ The `systemPromptOptions` field gives extensions access to the same structured d
Inside `before_agent_start`, `event.systemPrompt` and `ctx.getSystemPrompt()` both reflect the chained system prompt as of the current handler. Later `before_agent_start` handlers can still modify it again.
#### agent_start / agent_end
#### agent_start / agent_end / agent_settled
Fired once per user prompt.
`agent_start` fires when a low-level agent run begins. `agent_end` fires when that run ends, but Pi may still auto-retry, auto-compact and retry, or continue with queued follow-up messages. Use `agent_settled` for status integrations that need to know Pi will not continue running automatically.
```typescript
pi.on("agent_start", async (_event, ctx) => {});
pi.on("agent_end", async (event, ctx) => {
// event.messages - messages from this prompt
// event.messages - messages from this low-level run
});
pi.on("agent_settled", async (_event, ctx) => {
// ctx.isIdle() is true here unless another extension started a new run.
});
```
@@ -1000,7 +1005,7 @@ pi.on("tool_result", async (event, ctx) => {
### ctx.isIdle() / ctx.abort() / ctx.hasPendingMessages()
Control flow helpers.
Control flow helpers. `ctx.isIdle()` is false while Pi is processing an agent run, automatic retry, auto-compaction retry, or queued continuation.
### ctx.shutdown()
@@ -1082,7 +1087,7 @@ This reports the current base prompt inputs. It does not include per-turn `befor
### ctx.waitForIdle()
Wait for the agent to finish streaming:
Wait for the agent to fully settle, including automatic retries, auto-compaction retries, and queued continuations:
```typescript
pi.registerCommand("my-cmd", {