dynamic

package
v0.0.0-...-cdc720d Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatModel

type ChatModel struct {
	// Model is the underlying ChatModel to wrap
	Model model.BaseChatModel

	// GetOptionFunc is called before each Generate()/Stream() call to get dynamic options
	GetOptionFunc OptionFunc
}

ChatModel wraps a BaseChatModel and enables dynamic option modification. Before each Generate() or Stream() call, it: 1. Reads the current iteration state from the parent graph via compose.ProcessState 2. Calls GetOptionFunc to get dynamic options based on the current state 3. Increments the iteration counter 4. Merges dynamic options with any static options and calls the inner model

func (*ChatModel) Generate

func (d *ChatModel) Generate(ctx context.Context, input []*schema.Message, opts ...model.Option) (*schema.Message, error)

Generate implements model.BaseChatModel. It reads state, calls GetOptionFunc, increments iteration, and delegates to the inner model.

func (*ChatModel) GetType

func (d *ChatModel) GetType() string

GetType returns the type name for this component.

func (*ChatModel) IsCallbacksEnabled

func (d *ChatModel) IsCallbacksEnabled() bool

IsCallbacksEnabled implements components.Checker. Delegates to the inner model if it implements Checker.

func (*ChatModel) Stream

func (d *ChatModel) Stream(ctx context.Context, input []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)

Stream implements model.BaseChatModel. Same logic as Generate but returns a stream reader.

func (*ChatModel) WithTools

func (d *ChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)

WithTools implements model.ToolCallingChatModel. It creates a new ChatModel wrapping the result of the inner model's WithTools.

type OptionFunc

type OptionFunc func(ctx context.Context, input []*schema.Message, state *State) []model.Option

OptionFunc is the function signature for dynamic option generation. It is called before each ChatModel.Generate() call and returns options to be merged with any static options passed to the agent.

Parameters:

  • ctx: The context from the current request
  • input: The input messages being sent to the ChatModel
  • state: The current iteration state (can be modified)

Returns:

  • A slice of model.Option to be applied to this ChatModel call

type State

type State struct {
	// Iteration is the current iteration number (0-indexed).
	// It is incremented after each ChatModel.Generate() call.
	Iteration int

	// LastToolCalls stores the tool calls from the previous iteration.
	// This can be used to make decisions based on what tools were called.
	LastToolCalls []*schema.ToolCall

	// CustomData allows storing arbitrary data for custom decision logic.
	CustomData map[string]any
}

State holds the iteration state that persists across ReAct loop iterations. It is stored in the parent graph's local state and accessed via compose.ProcessState.

func NewState

func NewState() *State

NewState creates a new State with default values.

Jump to

Keyboard shortcuts

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