diff --git a/.changeset/witty-places-film.md b/.changeset/witty-places-film.md new file mode 100644 index 00000000000..c6a7b258ebe --- /dev/null +++ b/.changeset/witty-places-film.md @@ -0,0 +1,5 @@ +--- +"@effect/ai": patch +--- + +Fix Prompt.fromResponseParts when input contains a provider executed tool diff --git a/packages/ai/ai/src/Prompt.ts b/packages/ai/ai/src/Prompt.ts index b4051dbf62e..40e6bed078c 100644 --- a/packages/ai/ai/src/Prompt.ts +++ b/packages/ai/ai/src/Prompt.ts @@ -611,7 +611,8 @@ export const toolCallPart = (params: PartConstructorParams): ToolC * temperature: 22, * condition: "sunny", * humidity: 65 - * } + * }, + * providerExecuted: false * }) * ``` * @@ -635,6 +636,10 @@ export interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOp * The result returned by the tool execution. */ readonly result: unknown + /** + * Whether the tool was executed by the provider (true) or framework (false). + */ + readonly providerExecuted: boolean } /** @@ -660,6 +665,10 @@ export interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", To * The result returned by the tool execution. */ readonly result: unknown + /** + * Whether the tool was executed by the provider (true) or framework (false). + */ + readonly providerExecuted: boolean } /** @@ -683,6 +692,7 @@ export const ToolResultPart: Schema.Schema): User * result: { * temperature: 72, * condition: "sunny" - * } + * }, + * providerExecuted: false * }), * Prompt.makePart("text", { * text: "The weather in San Francisco is currently 72°F and sunny." @@ -1150,7 +1161,8 @@ export const assistantMessage = (params: MessageConstructorParams): Promp // Tool Result Parts case "tool-result": { - toolParts.push(makePart("tool-result", { + const toolPart = makePart("tool-result", { id: part.id, name: part.providerName ?? part.name, isFailure: part.isFailure, - result: part.encodedResult - })) + result: part.encodedResult, + providerExecuted: part.providerExecuted ?? false + }) + if (part.providerExecuted) { + assistantParts.push(toolPart) + } else { + toolParts.push(toolPart) + } } } }