@bluecopa/harness 0.1.0-snapshot.72 → 0.1.0-snapshot.73
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/package.json +1 -1
- package/src/loop/vercel-agent-loop.ts +15 -19
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { resolveToolChoice } from '../arc/types';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
import type { AgentAction, AgentMessage, AgentLoop, AgentStreamEvent, StepUsage, ToolCallAction, ToolBatchAction, PrepareStepContext, PrepareStepResult } from '../agent/types';
|
|
8
|
+
import { getTextContent } from '../agent/types';
|
|
8
9
|
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
type AnyTool = Tool<any, any>;
|
|
@@ -171,6 +172,8 @@ export interface VercelAgentLoopConfig {
|
|
|
171
172
|
/** System prompt — string or structured blocks with cache control markers. */
|
|
172
173
|
systemPrompt?: string | SystemPromptBlock[];
|
|
173
174
|
createModel?: ModelFactory;
|
|
175
|
+
/** @deprecated Prefer createModel. */
|
|
176
|
+
apiKey?: string;
|
|
174
177
|
/** Custom tool definitions. If provided, replaces built-in agentTools for LLM calls. */
|
|
175
178
|
tools?: Record<string, AnyTool>;
|
|
176
179
|
/** Tool choice for LLM calls. Supports per-turn callbacks. Default: 'auto'. */
|
|
@@ -184,12 +187,11 @@ export interface VercelAgentLoopConfig {
|
|
|
184
187
|
export class VercelAgentLoop implements AgentLoop {
|
|
185
188
|
private readonly model: string;
|
|
186
189
|
private readonly createModel: ModelFactory;
|
|
187
|
-
private readonly systemPrompt: string;
|
|
190
|
+
private readonly systemPrompt: string | SystemPromptBlock[];
|
|
188
191
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
|
-
private readonly cachedSystem: any;
|
|
190
192
|
private readonly tools: Record<string, AnyTool>;
|
|
191
193
|
private readonly validToolNames: Set<string>;
|
|
192
|
-
private readonly toolChoiceConfig
|
|
194
|
+
private readonly toolChoiceConfig: ToolChoiceConfig | undefined;
|
|
193
195
|
private readonly providerOptions: Record<string, unknown> | undefined;
|
|
194
196
|
private readonly prepareStep: VercelAgentLoopConfig['prepareStep'];
|
|
195
197
|
/** Track tool names called across steps for prepareStep context. */
|
|
@@ -220,11 +222,6 @@ export class VercelAgentLoop implements AgentLoop {
|
|
|
220
222
|
'When the task is fully complete, respond with a brief text summary (no tool call).',
|
|
221
223
|
].join(' ');
|
|
222
224
|
|
|
223
|
-
this.cachedSystem = [{
|
|
224
|
-
role: 'system' as const,
|
|
225
|
-
content: this.systemPrompt,
|
|
226
|
-
}];
|
|
227
|
-
|
|
228
225
|
if (config.apiKey) {
|
|
229
226
|
process.env.ANTHROPIC_API_KEY = config.apiKey;
|
|
230
227
|
}
|
|
@@ -246,12 +243,11 @@ export class VercelAgentLoop implements AgentLoop {
|
|
|
246
243
|
|
|
247
244
|
/** Resolve model + tools for this step via prepareStep callback. */
|
|
248
245
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
-
private resolveStep(): { model: string; tools: Record<string, any>; validNames: Set<string> } {
|
|
250
|
-
this.stepNumber++;
|
|
246
|
+
private resolveStep(stepNumber: number): { model: string; tools: Record<string, any>; validNames: Set<string> } {
|
|
251
247
|
if (!this.prepareStep) {
|
|
252
248
|
return { model: this.model, tools: this.tools, validNames: this.validToolNames };
|
|
253
249
|
}
|
|
254
|
-
const overrides = this.prepareStep({ stepNumber
|
|
250
|
+
const overrides = this.prepareStep({ stepNumber, toolCallHistory: this.toolCallHistory });
|
|
255
251
|
if (!overrides) {
|
|
256
252
|
return { model: this.model, tools: this.tools, validNames: this.validToolNames };
|
|
257
253
|
}
|
|
@@ -285,14 +281,14 @@ export class VercelAgentLoop implements AgentLoop {
|
|
|
285
281
|
async nextAction(messages: AgentMessage[]): Promise<AgentAction> {
|
|
286
282
|
const currentStep = this.step++;
|
|
287
283
|
|
|
288
|
-
const { model, tools, validNames } = this.resolveStep();
|
|
284
|
+
const { model, tools, validNames } = this.resolveStep(currentStep + 1);
|
|
289
285
|
|
|
290
286
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
287
|
const result = await (generateText as any)({
|
|
292
|
-
model: this.createModel(
|
|
293
|
-
tools
|
|
288
|
+
model: this.createModel(model),
|
|
289
|
+
tools,
|
|
294
290
|
toolChoice: resolveToolChoice(this.toolChoiceConfig, currentStep),
|
|
295
|
-
system: this.
|
|
291
|
+
system: this.buildSystemParam(),
|
|
296
292
|
messages: toModelMessages(messages),
|
|
297
293
|
stopWhen: stepCountIs(1),
|
|
298
294
|
...(this.providerOptions ? { providerOptions: this.providerOptions } : {}),
|
|
@@ -339,14 +335,14 @@ export class VercelAgentLoop implements AgentLoop {
|
|
|
339
335
|
async *streamAction(messages: AgentMessage[]): AsyncGenerator<AgentStreamEvent> {
|
|
340
336
|
const currentStep = this.step++;
|
|
341
337
|
|
|
342
|
-
const { model, tools, validNames } = this.resolveStep();
|
|
338
|
+
const { model, tools, validNames } = this.resolveStep(currentStep + 1);
|
|
343
339
|
|
|
344
340
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
345
341
|
const result = (streamText as any)({
|
|
346
|
-
model: this.createModel(
|
|
347
|
-
tools
|
|
342
|
+
model: this.createModel(model),
|
|
343
|
+
tools,
|
|
348
344
|
toolChoice: resolveToolChoice(this.toolChoiceConfig, currentStep),
|
|
349
|
-
system: this.
|
|
345
|
+
system: this.buildSystemParam(),
|
|
350
346
|
messages: toModelMessages(messages),
|
|
351
347
|
stopWhen: stepCountIs(1),
|
|
352
348
|
...(this.providerOptions ? { providerOptions: this.providerOptions } : {}),
|