@compilr-dev/agents 0.3.23 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +10 -1
- package/dist/hooks/manager.d.ts +1 -0
- package/dist/hooks/manager.js +5 -2
- package/dist/hooks/types.d.ts +10 -0
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -1700,15 +1700,23 @@ export class Agent {
|
|
|
1700
1700
|
const filterSet = new Set(options.toolFilter);
|
|
1701
1701
|
tools = tools.filter((tool) => filterSet.has(tool.name));
|
|
1702
1702
|
}
|
|
1703
|
-
// Run beforeLLM hooks (can modify messages and
|
|
1703
|
+
// Run beforeLLM hooks (can modify messages, tools, and system prompt)
|
|
1704
1704
|
if (this.hooksManager) {
|
|
1705
1705
|
const llmHookResult = await this.hooksManager.runBeforeLLM({
|
|
1706
1706
|
...hookContext,
|
|
1707
1707
|
messages,
|
|
1708
1708
|
tools,
|
|
1709
|
+
systemPrompt: systemContent,
|
|
1709
1710
|
});
|
|
1710
1711
|
messages = llmHookResult.messages;
|
|
1711
1712
|
tools = llmHookResult.tools;
|
|
1713
|
+
// If a hook modified the system prompt, update messages[0]
|
|
1714
|
+
if (llmHookResult.systemPrompt !== systemContent) {
|
|
1715
|
+
systemContent = llmHookResult.systemPrompt;
|
|
1716
|
+
if (messages.length > 0 && messages[0].role === 'system') {
|
|
1717
|
+
messages[0] = { role: 'system', content: systemContent };
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1712
1720
|
}
|
|
1713
1721
|
// Call LLM
|
|
1714
1722
|
emit({ type: 'llm_start' });
|
|
@@ -1772,6 +1780,7 @@ export class Agent {
|
|
|
1772
1780
|
...hookContext,
|
|
1773
1781
|
messages,
|
|
1774
1782
|
tools,
|
|
1783
|
+
systemPrompt: systemContent,
|
|
1775
1784
|
text,
|
|
1776
1785
|
toolUses,
|
|
1777
1786
|
usage: usage
|
package/dist/hooks/manager.d.ts
CHANGED
package/dist/hooks/manager.js
CHANGED
|
@@ -330,6 +330,7 @@ export class HooksManager {
|
|
|
330
330
|
async runBeforeLLM(context) {
|
|
331
331
|
let messages = context.messages;
|
|
332
332
|
let tools = context.tools;
|
|
333
|
+
let systemPrompt = context.systemPrompt;
|
|
333
334
|
for (const registered of this.beforeLLMHooks) {
|
|
334
335
|
const start = Date.now();
|
|
335
336
|
try {
|
|
@@ -339,7 +340,7 @@ export class HooksManager {
|
|
|
339
340
|
hookId: registered.id,
|
|
340
341
|
hookName: registered.name,
|
|
341
342
|
});
|
|
342
|
-
const result = await registered.hook({ ...context, messages, tools });
|
|
343
|
+
const result = await registered.hook({ ...context, messages, tools, systemPrompt });
|
|
343
344
|
this.emitEvent({
|
|
344
345
|
type: 'hook:completed',
|
|
345
346
|
hookType: 'beforeLLM',
|
|
@@ -353,6 +354,8 @@ export class HooksManager {
|
|
|
353
354
|
messages = hookResult.messages;
|
|
354
355
|
if (hookResult.tools)
|
|
355
356
|
tools = hookResult.tools;
|
|
357
|
+
if (hookResult.systemPrompt !== undefined)
|
|
358
|
+
systemPrompt = hookResult.systemPrompt;
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
361
|
catch (error) {
|
|
@@ -365,7 +368,7 @@ export class HooksManager {
|
|
|
365
368
|
});
|
|
366
369
|
}
|
|
367
370
|
}
|
|
368
|
-
return { messages, tools };
|
|
371
|
+
return { messages, tools, systemPrompt };
|
|
369
372
|
}
|
|
370
373
|
/**
|
|
371
374
|
* Run after:llm hooks
|
package/dist/hooks/types.d.ts
CHANGED
|
@@ -94,6 +94,11 @@ export interface LLMHookContext extends HookContext {
|
|
|
94
94
|
* Tool definitions available to LLM
|
|
95
95
|
*/
|
|
96
96
|
tools: ToolDefinition[];
|
|
97
|
+
/**
|
|
98
|
+
* Current system prompt (fully assembled, including anchors).
|
|
99
|
+
* Hooks can read this and return a modified version in BeforeLLMHookResult.
|
|
100
|
+
*/
|
|
101
|
+
systemPrompt: string;
|
|
97
102
|
}
|
|
98
103
|
/**
|
|
99
104
|
* Result from before:llm hook that modifies messages or tools
|
|
@@ -107,6 +112,11 @@ export interface BeforeLLMHookResult {
|
|
|
107
112
|
* Modified tools (optional, original used if not provided)
|
|
108
113
|
*/
|
|
109
114
|
tools?: ToolDefinition[];
|
|
115
|
+
/**
|
|
116
|
+
* Modified system prompt (optional, original used if not provided).
|
|
117
|
+
* When returned, messages[0] (system message) is updated automatically.
|
|
118
|
+
*/
|
|
119
|
+
systemPrompt?: string;
|
|
110
120
|
}
|
|
111
121
|
/**
|
|
112
122
|
* Hook called before LLM call.
|