tool

package
v1.0.0-alpha.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPermissionDenied = errors.New("tool: permission denied")

Functions

func JSONSchema

func JSONSchema(value any) json.RawMessage

func Node

func Node[S any](id string, spec NodeSpec[S]) graph.NodeSpec[S]

func WithAdjuster

func WithAdjuster(ctx context.Context, adjuster Adjuster) context.Context

func WithRegistry

func WithRegistry(ctx context.Context, registry *Registry) context.Context

Types

type Adjuster

type Adjuster interface {
	AfterTool(context.Context, AfterToolRequest) (AfterToolResult, error)
}

func AdjusterFromContext

func AdjusterFromContext(ctx context.Context) (Adjuster, bool)

type AfterToolRequest

type AfterToolRequest struct {
	NodeID   string            `json:"node_id"`
	Call     Call              `json:"call"`
	Result   Result            `json:"result"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type AfterToolResult

type AfterToolResult struct {
	Result *Result `json:"result,omitempty"`
}

type Call

type Call struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

func FromLLMToolCalls

func FromLLMToolCalls(calls []llm.ToolCall) []Call

type Definition

type Definition[TIn, TOut any] struct {
	// contains filtered or unexported fields
}

func Define

func Define[TIn, TOut any](id string) *Definition[TIn, TOut]

func (*Definition[TIn, TOut]) Description

func (d *Definition[TIn, TOut]) Description(text string) *Definition[TIn, TOut]

func (*Definition[TIn, TOut]) Execute

func (d *Definition[TIn, TOut]) Execute(fn ExecuteFunc[TIn, TOut]) *Definition[TIn, TOut]

func (*Definition[TIn, TOut]) ExecuteJSON

func (d *Definition[TIn, TOut]) ExecuteJSON(ctx context.Context, input json.RawMessage) (Result, error)

func (*Definition[TIn, TOut]) InputSchema

func (d *Definition[TIn, TOut]) InputSchema(schema any) *Definition[TIn, TOut]

func (*Definition[TIn, TOut]) Permission

func (d *Definition[TIn, TOut]) Permission(policy PermissionPolicy[TIn]) *Definition[TIn, TOut]

func (*Definition[TIn, TOut]) PermissionJSON

func (d *Definition[TIn, TOut]) PermissionJSON(ctx context.Context, input json.RawMessage) (hitl.Request, bool, error)

func (*Definition[TIn, TOut]) Spec

func (d *Definition[TIn, TOut]) Spec() Spec

type Executable

type Executable interface {
	Spec() Spec
	ExecuteJSON(context.Context, json.RawMessage) (Result, error)
	PermissionJSON(context.Context, json.RawMessage) (hitl.Request, bool, error)
}

type ExecuteFunc

type ExecuteFunc[TIn, TOut any] func(context.Context, TIn) (TOut, error)

type NodeSpec

type NodeSpec[S any] struct {
	Registry         *Registry
	ToolIDs          []string
	Calls            func(context.Context, S) ([]Call, error)
	Output           func(context.Context, S, []Result) (graph.Command[S], error)
	Error            func(context.Context, S, Call, error) (graph.Command[S], error)
	ContinueOnError  bool
	MaxConcurrency   int
	ProgressInterval time.Duration
	Metadata         map[string]string
}

type PermissionPolicy

type PermissionPolicy[TIn any] func(context.Context, TIn) (hitl.Request, bool, error)

func RequireApproval

func RequireApproval[TIn any](reason string) PermissionPolicy[TIn]

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func RegistryFromContext

func RegistryFromContext(ctx context.Context) (*Registry, bool)

func (*Registry) Get

func (r *Registry) Get(name string) (Executable, bool)

func (*Registry) LLMSpecs

func (r *Registry) LLMSpecs(names ...string) ([]llm.ToolSpec, error)

func (*Registry) Register

func (r *Registry) Register(item Executable) error

func (*Registry) Specs

func (r *Registry) Specs(names ...string) ([]Spec, error)

type Result

type Result struct {
	CallID  string          `json:"call_id"`
	Name    string          `json:"name"`
	Content string          `json:"content,omitempty"`
	Raw     json.RawMessage `json:"raw,omitempty"`
	Error   string          `json:"error,omitempty"`
}

func ErrorResult

func ErrorResult(call Call, err error) Result

func (Result) Message

func (r Result) Message() llm.Message

type Spec

type Spec struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"input_schema,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL