mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 20:03:05 +00:00
Allow extensions to modify system prompt in before_agent_start
- Add systemPrompt to BeforeAgentStartEvent so extensions can see current prompt - Change systemPromptAppend to systemPrompt in BeforeAgentStartEventResult for full replacement - Extensions can now chain modifications (each sees the result of previous) - Update ssh.ts to replace local cwd with remote cwd in system prompt - Update pirate.ts, claude-rules.ts, preset.ts to use new API fixes #575
This commit is contained in:
parent
0774db2e5a
commit
17cb328ca1
10 changed files with 65 additions and 27 deletions
|
|
@ -255,7 +255,7 @@ pi starts
|
|||
▼
|
||||
user sends prompt ─────────────────────────────────────────┐
|
||||
│ │
|
||||
├─► before_agent_start (can inject message, append to system prompt)
|
||||
├─► before_agent_start (can inject message, modify system prompt)
|
||||
├─► agent_start │
|
||||
│ │
|
||||
│ ┌─── turn (repeats while LLM calls tools) ───┐ │
|
||||
|
|
@ -414,12 +414,13 @@ pi.on("session_shutdown", async (_event, ctx) => {
|
|||
|
||||
#### before_agent_start
|
||||
|
||||
Fired after user submits prompt, before agent loop. Can inject a message and/or append to the system prompt.
|
||||
Fired after user submits prompt, before agent loop. Can inject a message and/or modify the system prompt.
|
||||
|
||||
```typescript
|
||||
pi.on("before_agent_start", async (event, ctx) => {
|
||||
// event.prompt - user's prompt text
|
||||
// event.images - attached images (if any)
|
||||
// event.systemPrompt - current system prompt
|
||||
|
||||
return {
|
||||
// Inject a persistent message (stored in session, sent to LLM)
|
||||
|
|
@ -428,13 +429,13 @@ pi.on("before_agent_start", async (event, ctx) => {
|
|||
content: "Additional context for the LLM",
|
||||
display: true,
|
||||
},
|
||||
// Append to system prompt for this turn only
|
||||
systemPromptAppend: "Extra instructions for this turn...",
|
||||
// Replace the system prompt for this turn (chained across extensions)
|
||||
systemPrompt: event.systemPrompt + "\n\nExtra instructions for this turn...",
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
**Examples:** [claude-rules.ts](../examples/extensions/claude-rules.ts), [pirate.ts](../examples/extensions/pirate.ts), [plan-mode.ts](../examples/extensions/plan-mode.ts), [preset.ts](../examples/extensions/preset.ts)
|
||||
**Examples:** [claude-rules.ts](../examples/extensions/claude-rules.ts), [pirate.ts](../examples/extensions/pirate.ts), [plan-mode.ts](../examples/extensions/plan-mode.ts), [preset.ts](../examples/extensions/preset.ts), [ssh.ts](../examples/extensions/ssh.ts)
|
||||
|
||||
#### agent_start / agent_end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue