Skip to content

Commit f21f034

Browse files
authored
Fix Prompt.fromResponseParts when input contains a provider executed tool (#5944)
1 parent 9f74ba1 commit f21f034

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.changeset/witty-places-film.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/ai": patch
3+
---
4+
5+
Fix Prompt.fromResponseParts when input contains a provider executed tool

packages/ai/ai/src/Prompt.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ export const toolCallPart = (params: PartConstructorParams<ToolCallPart>): ToolC
611611
* temperature: 22,
612612
* condition: "sunny",
613613
* humidity: 65
614-
* }
614+
* },
615+
* providerExecuted: false
615616
* })
616617
* ```
617618
*
@@ -635,6 +636,10 @@ export interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOp
635636
* The result returned by the tool execution.
636637
*/
637638
readonly result: unknown
639+
/**
640+
* Whether the tool was executed by the provider (true) or framework (false).
641+
*/
642+
readonly providerExecuted: boolean
638643
}
639644

640645
/**
@@ -660,6 +665,10 @@ export interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", To
660665
* The result returned by the tool execution.
661666
*/
662667
readonly result: unknown
668+
/**
669+
* Whether the tool was executed by the provider (true) or framework (false).
670+
*/
671+
readonly providerExecuted: boolean
663672
}
664673

665674
/**
@@ -683,6 +692,7 @@ export const ToolResultPart: Schema.Schema<ToolResultPart, ToolResultPartEncoded
683692
name: Schema.String,
684693
isFailure: Schema.Boolean,
685694
result: Schema.Unknown,
695+
providerExecuted: Schema.Boolean,
686696
options: Schema.optionalWith(ProviderOptions, { default: constEmptyObject })
687697
}).pipe(
688698
Schema.attachPropertySignature(PartTypeId, PartTypeId),
@@ -1036,7 +1046,8 @@ export const userMessage = (params: MessageConstructorParams<UserMessage>): User
10361046
* result: {
10371047
* temperature: 72,
10381048
* condition: "sunny"
1039-
* }
1049+
* },
1050+
* providerExecuted: false
10401051
* }),
10411052
* Prompt.makePart("text", {
10421053
* text: "The weather in San Francisco is currently 72°F and sunny."
@@ -1150,7 +1161,8 @@ export const assistantMessage = (params: MessageConstructorParams<AssistantMessa
11501161
* { title: "TypeScript Handbook", url: "https://..." },
11511162
* { title: "Effective TypeScript", url: "https://..." }
11521163
* ]
1153-
* }
1164+
* },
1165+
* providerExecuted: false
11541166
* })
11551167
* ]
11561168
* })
@@ -1624,12 +1636,18 @@ export const fromResponseParts = (parts: ReadonlyArray<Response.AnyPart>): Promp
16241636

16251637
// Tool Result Parts
16261638
case "tool-result": {
1627-
toolParts.push(makePart("tool-result", {
1639+
const toolPart = makePart("tool-result", {
16281640
id: part.id,
16291641
name: part.providerName ?? part.name,
16301642
isFailure: part.isFailure,
1631-
result: part.encodedResult
1632-
}))
1643+
result: part.encodedResult,
1644+
providerExecuted: part.providerExecuted ?? false
1645+
})
1646+
if (part.providerExecuted) {
1647+
assistantParts.push(toolPart)
1648+
} else {
1649+
toolParts.push(toolPart)
1650+
}
16331651
}
16341652
}
16351653
}

0 commit comments

Comments
 (0)