Minor Changes
-
#5614
c63e658
Thanks @IMax153! - Previously, tool call handler errors were always raised as an expected error in the EffectE
channel at the point of execution of the tool call handler (i.e. when agenerate*
method is invoked on aLanguageModel
).With this PR, the end user now has control over whether tool call handler errors should be raised as an Effect error, or returned by the SDK to allow, for example, sending that error information to another application.
Tool Call Specification
The
Tool.make
andTool.providerDefined
constructors now take an extra optional parameter calledfailureMode
, which can be set to either"error"
or"return"
.import { Tool } from "@effect/ai" import { Schema } from "effect" const MyTool = Tool.make("MyTool", { description: "My special tool", failureMode: "return" // "error" (default) or "return" parameters: { myParam: Schema.String }, success: Schema.Struct({ mySuccess: Schema.String }), failure: Schema.Struct({ myFailure: Schema.String }) })
The semantics of
failureMode
are as follows:- If set to
"error"
(the default), errors that occur during tool call handler execution will be returned in the error channel of the calling effect - If set to
"return"
, errors that occur during tool call handler execution will be captured and returned as part of the tool call result
Response - Tool Result Parts
The
result
field of a"tool-result"
part of a large language model provider response is now represented as anEither
.- If the
result
is aLeft
, theresult
will be thefailure
specified in the tool call specification - If the
result
is aRight
, theresult
will be thesuccess
specified in the tool call specification
This is only relevant if the end user sets
failureMode
to"return"
. If set to"error"
(the default), then theresult
property will always be aRight
with the successful result of the tool call handler.Similarly the
encodedResult
field of a"tool-result"
part will be represented as anEitherEncoded
, where:{ _tag: "Left", left: <failure> }
represents a tool call handler failure{ _tag: "Right", right: <success> }
represents a tool call handler success
Prompt - Tool Result Parts
The
result
field of a"tool-result"
part of a prompt will now only accept anEitherEncoded
as specified above. - If set to
Patch Changes
- Updated dependencies [
6ae2f5d
]:- effect@3.18.4