Documentation
¶
Overview ¶
Package toolautocall provides the middleware that automatically invokes the function tools a model calls and feeds their results back for the next turn. Supporting providers add it by default and expose Config for customization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(cfg Config) agent.Middleware
New creates a new function-invoking chat client that wraps the provided client.
Types ¶
type Config ¶
type Config struct {
// Logger receives diagnostic events about function invocation.
// If nil, no events are logged.
Logger *slog.Logger
// LogSensitiveData controls whether sensitive function arguments and results
// are included in logs. The default is false.
LogSensitiveData bool
// AdditionalTools are tools the middleware can invoke without adding them to
// provider requests. Request tools supplied through agent options take
// precedence; this collection is consulted afterward, which is useful when the
// provider is already configured with tool declarations out of band.
AdditionalTools []tool.Tool
// IncludeDetailedErrors controls whether tool error details are included in
// the function result sent back to the provider. When false, the provider sees
// a generic error message while the raw error remains available on the
// FunctionResultContent and is rethrown if the consecutive-error limit is
// exceeded. The default is false.
IncludeDetailedErrors bool
// TerminateOnUnknownCalls controls whether a request to call an unknown tool
// stops the function-calling loop. When false, the middleware returns a
// generated "not found" function result to the provider. When true, the
// original response is returned so the caller can handle the tool call. A known
// schema tool that is not invocable always stops the loop. The default is false.
TerminateOnUnknownCalls bool
// AllowConcurrentInvocations controls whether multiple function calls from the
// same provider response may execute in parallel. When false, function calls are
// processed serially. The default is false.
AllowConcurrentInvocations bool
// MaximumConsecutiveErrorsPerRequest is the number of consecutive failing
// function-invocation iterations allowed before the middleware returns the
// aggregated invocation errors to the caller. A successful iteration resets the
// count. When nil, the default of 3 is used. Set to new(0) to fail on the
// first tool error.
MaximumConsecutiveErrorsPerRequest *int
// MaximumIterationsPerRequest is the maximum number of tool-invocation rounds
// performed for a single run. When the limit is reached, the middleware makes a
// final provider request without schema tools so no more local function calls
// are requested. When nil, the default of 40 is used. Zero disables the
// middleware as described by [Config]. Negative values are invalid.
MaximumIterationsPerRequest *int
// NewID generates synthetic IDs for generated tool-result messages and
// approval-related fallback messages. If nil, a canonical dashed UUID is used.
NewID func() string
// DisableApprovalResponseBinding disables session-backed validation that
// binds approval responses to approval requests surfaced by the framework.
// Binding is enabled by default.
DisableApprovalResponseBinding bool
// DisableApprovalNotRequiredFunctionBypassing disables hiding and
// automatically approving safe function calls returned alongside calls that
// require approval. Bypassing is enabled by default.
DisableApprovalNotRequiredFunctionBypassing bool
}
Config configures the automatic tool invocation middleware.
When a provider response contains function call content, the middleware looks up the matching tool, invokes it, sends the generated function result back to the provider, and repeats this loop until there are no more function calls or another stop condition is met. To disable the middleware, set MaximumIterationsPerRequest to new(0). A disabled middleware delegates once without changing the request options, messages, or response updates.