|
1 | 1 | # @effect/ai-amazon-bedrock |
2 | 2 |
|
| 3 | +## 0.11.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- [#5621](https://github.com/Effect-TS/effect/pull/5621) [`4c3bdfb`](https://github.com/Effect-TS/effect/commit/4c3bdfbcbc2dcd7ecd6321df3e4a504af19de825) Thanks @IMax153! - Remove `Either` / `EitherEncoded` from tool call results. |
| 8 | + |
| 9 | + Specifically, the encoding of tool call results as an `Either` / `EitherEncoded` has been removed and is replaced by encoding the tool call success / failure directly into the `result` property. |
| 10 | + |
| 11 | + To allow type-safe discrimination between a tool call result which was a success vs. one that was a failure, an `isFailure` property has also been added to the `"tool-result"` part. If `isFailure` is `true`, then the tool call handler result was an error. |
| 12 | + |
| 13 | + ```ts |
| 14 | + import * as AnthropicClient from "@effect/ai-anthropic/AnthropicClient" |
| 15 | + import * as AnthropicLanguageModel from "@effect/ai-anthropic/AnthropicLanguageModel" |
| 16 | + import * as LanguageModel from "@effect/ai/LanguageModel" |
| 17 | + import * as Tool from "@effect/ai/Tool" |
| 18 | + import * as Toolkit from "@effect/ai/Toolkit" |
| 19 | + import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient" |
| 20 | + import { Config, Effect, Layer, Schema, Stream } from "effect" |
| 21 | + |
| 22 | + const Claude = AnthropicLanguageModel.model("claude-4-sonnet-20250514") |
| 23 | + |
| 24 | + const MyTool = Tool.make("MyTool", { |
| 25 | + description: "An example of a tool with success and failure types", |
| 26 | + failureMode: "return", // Return errors in the response |
| 27 | + parameters: { bar: Schema.Number }, |
| 28 | + success: Schema.Number, |
| 29 | + failure: Schema.Struct({ reason: Schema.Literal("reason-1", "reason-2") }) |
| 30 | + }) |
| 31 | + |
| 32 | + const MyToolkit = Toolkit.make(MyTool) |
| 33 | + |
| 34 | + const MyToolkitLayer = MyToolkit.toLayer({ |
| 35 | + MyTool: () => Effect.succeed(42) |
| 36 | + }) |
| 37 | + |
| 38 | + const program = LanguageModel.streamText({ |
| 39 | + prompt: "Tell me about the meaning of life", |
| 40 | + toolkit: MyToolkit |
| 41 | + }).pipe( |
| 42 | + Stream.runForEach((part) => { |
| 43 | + if (part.type === "tool-result" && part.name === "MyTool") { |
| 44 | + // The `isFailure` property can be used to discriminate whether the result |
| 45 | + // of a tool call is a success or a failure |
| 46 | + if (part.isFailure) { |
| 47 | + part.result |
| 48 | + // ^? { readonly reason: "reason-1" | "reason-2"; } |
| 49 | + } else { |
| 50 | + part.result |
| 51 | + // ^? number |
| 52 | + } |
| 53 | + } |
| 54 | + return Effect.void |
| 55 | + }), |
| 56 | + Effect.provide(Claude) |
| 57 | + ) |
| 58 | + |
| 59 | + const Anthropic = AnthropicClient.layerConfig({ |
| 60 | + apiKey: Config.redacted("ANTHROPIC_API_KEY") |
| 61 | + }).pipe(Layer.provide(NodeHttpClient.layerUndici)) |
| 62 | + |
| 63 | + program.pipe(Effect.provide([Anthropic, MyToolkitLayer]), Effect.runPromise) |
| 64 | + ``` |
| 65 | + |
| 66 | +### Patch Changes |
| 67 | + |
| 68 | +- Updated dependencies [[`4c3bdfb`](https://github.com/Effect-TS/effect/commit/4c3bdfbcbc2dcd7ecd6321df3e4a504af19de825)]: |
| 69 | + - @effect/ai-anthropic@0.21.0 |
| 70 | + - @effect/ai@0.31.0 |
| 71 | + |
3 | 72 | ## 0.10.0 |
4 | 73 |
|
5 | 74 | ### Minor Changes |
|
0 commit comments