Repository navigation
Expand file tree
/
Copy pathasync_params.go
More file actions
69 lines (62 loc) · 2.33 KB
/
Copy pathasync_params.go
File metadata and controls
69 lines (62 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package agent
import (
"context"
"github.com/OpenRouterTeam/go-sdk/models/components"
)
type DynamicValue[T any] func(context.Context, TurnContext) (T, error)
type CallModelInput struct {
Model string
ModelFunc DynamicValue[string]
Input any
Tools []Tool
StopWhen []StopCondition
AllowFinalResponse any
// StrictFinalResponse: when true, skips the one-shot retry that would
// otherwise fire when a completed run's final response has no output
// after at least one tool round. Default false: that empty final is
// retried once via a `toolChoice: none` resend. Either way an empty
// final response is never a hard error here — unlike upstream's
// `validateFinalResponse`, an empty `Output` items array is not on its
// own a reliable invalidity signal against go-sdk's response shape,
// which also carries a separate `OutputText` convenience field. See
// upstreamer-changelog.md's compatibility note.
StrictFinalResponse bool
State *ConversationState
StateAccessor StateAccessor
Context ContextInput
Approval ToolApprovalCheck
ApproveToolCalls []string
RejectToolCalls []string
Request components.ResponsesRequest
MetadataLevel *components.MetadataLevel
MaxTurns int
BeforeTurn func(context.Context, TurnContext) error
AfterTurn func(context.Context, TurnContext, StepResult) error
AdditionalInstructions string
InstructionsFunc DynamicValue[string]
// Hooks accepts either a *HooksManager or an InlineHookConfig. See
// ResolveHooks. nil means no hooks.
Hooks any
}
type CallModelInputWithState = CallModelInput
type ResolvedCallModelInput = CallModelInput
func HasAsyncFunctions(input CallModelInput) bool {
return input.ModelFunc != nil || input.InstructionsFunc != nil
}
func ResolveAsyncFunctions(ctx context.Context, input CallModelInput, turn TurnContext) (ResolvedCallModelInput, error) {
if input.ModelFunc != nil {
model, err := input.ModelFunc(ctx, turn)
if err != nil {
return input, err
}
input.Model = model
}
if input.InstructionsFunc != nil {
instructions, err := input.InstructionsFunc(ctx, turn)
if err != nil {
return input, err
}
input.AdditionalInstructions = instructions
}
return input, nil
}