Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yummy-papayas-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/ai": patch
---

Add support for "providerOptions" in `DurableAgent`
3 changes: 3 additions & 0 deletions packages/ai/src/agent/do-stream-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
LanguageModelV2StreamPart,
LanguageModelV2ToolCall,
LanguageModelV2ToolResultPart,
SharedV2ProviderOptions,
} from '@ai-sdk/provider';
import {
gateway,
Expand All @@ -24,6 +25,7 @@ export async function doStreamStep(
writable: WritableStream<UIMessageChunk>,
tools?: LanguageModelV2CallOptions['tools'],
options?: {
providerOptions?: SharedV2ProviderOptions;
sendStart?: boolean;
}
) {
Expand All @@ -44,6 +46,7 @@ export async function doStreamStep(
const result = await model.doStream({
prompt: conversationPrompt,
tools,
providerOptions: options?.providerOptions,
});

let finish: FinishPart | undefined;
Expand Down
11 changes: 11 additions & 0 deletions packages/ai/src/agent/durable-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
LanguageModelV2,
LanguageModelV2ToolCall,
LanguageModelV2ToolResultPart,
SharedV2ProviderOptions,
} from '@ai-sdk/provider';
import {
asSchema,
Expand Down Expand Up @@ -39,6 +40,13 @@ export interface DurableAgentOptions {
*/
model: string | (() => Promise<LanguageModelV2>);

/**
* Additional provider-specific options. They are passed through
* to the provider from the AI SDK and enable provider-specific
* functionality that can be fully encapsulated in the provider.
*/
providerOptions?: SharedV2ProviderOptions;

/**
* A set of tools available to the agent.
* Tools can be implemented as workflow steps for automatic retries and persistence,
Expand Down Expand Up @@ -137,11 +145,13 @@ export interface DurableAgentStreamOptions {
*/
export class DurableAgent {
private model: string | (() => Promise<LanguageModelV2>);
private providerOptions?: SharedV2ProviderOptions;
private tools: DurableAgentToolSet;
private system?: string;

constructor(options: DurableAgentOptions) {
this.model = options.model;
this.providerOptions = options.providerOptions;
this.tools = options.tools ?? {};
this.system = options.system;
}
Expand All @@ -164,6 +174,7 @@ export class DurableAgent {

const iterator = streamTextIterator({
model: this.model,
providerOptions: this.providerOptions,
tools: this.tools,
writable: options.writable,
prompt: modelPrompt,
Expand Down
6 changes: 5 additions & 1 deletion packages/ai/src/agent/stream-text-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import type {
LanguageModelV2Prompt,
LanguageModelV2ToolCall,
LanguageModelV2ToolResultPart,
SharedV2ProviderOptions,
} from '@ai-sdk/provider';
import type {
StepResult,
StreamTextOnStepFinishCallback,
UIMessageChunk,
} from 'ai';
import type { DurableAgentToolSet } from './durable-agent.js';
import { doStreamStep, type ModelStopCondition } from './do-stream-step.js';
import type { DurableAgentToolSet } from './durable-agent.js';
import { toolsToModelTools } from './tools-to-model-tools.js';

// This runs in the workflow context
Expand All @@ -19,6 +20,7 @@ export async function* streamTextIterator({
tools = {},
writable,
model,
providerOptions,
stopConditions,
sendStart = true,
onStepFinish,
Expand All @@ -27,6 +29,7 @@ export async function* streamTextIterator({
tools: DurableAgentToolSet;
writable: WritableStream<UIMessageChunk>;
model: string | (() => Promise<LanguageModelV2>);
providerOptions?: SharedV2ProviderOptions;
stopConditions?: ModelStopCondition[] | ModelStopCondition;
sendStart?: boolean;
onStepFinish?: StreamTextOnStepFinishCallback<any>;
Expand All @@ -48,6 +51,7 @@ export async function* streamTextIterator({
writable,
toolsToModelTools(tools),
{
providerOptions,
sendStart: sendStart && isFirstIteration,
}
);
Expand Down
Loading