Documentation
¶
Index ¶
- func DurableRun[T any](ctx context.Context, executor DurableExecutor, name string, ...) (T, error)
- func NilCallback(msg *responses.ResponseChunk)
- type BaseTool
- type ChatHistory
- type DurableExecutor
- type HistorySummarizer
- type NoOpExecutor
- func (e *NoOpExecutor) Checkpoint(ctx context.Context, name string) error
- func (e *NoOpExecutor) Get(ctx context.Context, key string) (any, bool, error)
- func (e *NoOpExecutor) Run(ctx context.Context, name string, fn func(ctx context.Context) (any, error)) (any, error)
- func (e *NoOpExecutor) Set(ctx context.Context, key string, value any) error
- type RunState
- func (s *RunState) ClearPendingTools()
- func (s *RunState) HasToolsAwaitingApproval() bool
- func (s *RunState) IsComplete() bool
- func (s *RunState) IsPaused() bool
- func (s *RunState) NextStep() Step
- func (s *RunState) PromoteAwaitingToApproval()
- func (s *RunState) ToMeta(traceid string) map[string]any
- func (s *RunState) TransitionToAwaitApproval(tools []responses.FunctionCallMessage)
- func (s *RunState) TransitionToComplete()
- func (s *RunState) TransitionToExecuteTools(tools []responses.FunctionCallMessage)
- func (s *RunState) TransitionToLLM()
- type RunStatus
- type Step
- type SummaryResult
- type SystemPromptProvider
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DurableRun ¶
func DurableRun[T any](ctx context.Context, executor DurableExecutor, name string, fn func(ctx context.Context) (T, error)) (T, error)
DurableRun is a helper function for type-safe durable execution. Usage: result, err := DurableRun[MyType](ctx, executor, "step-name", func(ctx) (MyType, error) { ... })
func NilCallback ¶
func NilCallback(msg *responses.ResponseChunk)
Types ¶
type BaseTool ¶
func (*BaseTool) NeedApproval ¶
type ChatHistory ¶
type ChatHistory interface {
// AddMessages adds new messages into a list in-memory
AddMessages(ctx context.Context, messages []responses.InputMessageUnion, usage *responses.Usage)
// GetMessages returns a list of messages from in-memory. It handles summarization if enabled
GetMessages(ctx context.Context) ([]responses.InputMessageUnion, error)
// LoadMessages fetches all the messages of the thread from persistent storage into memory
LoadMessages(ctx context.Context, namespace string, previousMessageID string) ([]responses.InputMessageUnion, error)
// SaveMessages saves the messages to persistent storage
SaveMessages(ctx context.Context, meta map[string]any) error
// GetMeta returns the meta from the most recent message
GetMeta() map[string]any
// GetMessageID returns the current run id
GetMessageID() string
}
type DurableExecutor ¶
type DurableExecutor interface {
// Run executes a function with durability guarantees.
// If the process crashes after fn() completes, the result is restored
// from the checkpoint instead of re-executing fn().
//
// The name parameter is used to identify the checkpoint (must be unique per step).
Run(ctx context.Context, name string, fn func(ctx context.Context) (any, error)) (any, error)
// Set stores a value in durable state.
// The value persists across crashes and can be retrieved with Get().
Set(ctx context.Context, key string, value any) error
// Get retrieves a value from durable state.
// Returns the value and true if found, or nil and false if not found.
Get(ctx context.Context, key string) (any, bool, error)
// Checkpoint creates an explicit checkpoint marker.
// Useful for marking progress without storing data.
Checkpoint(ctx context.Context, name string) error
}
DurableExecutor provides an abstraction for durable/checkpointed execution. Implementations can provide different durability guarantees: - NoOpExecutor: No durability (default, existing behavior) - RestateExecutor: Durable via Restate - TemporalExecutor: Durable via Temporal (future) - RedisExecutor: Durable via Redis Streams (future)
type HistorySummarizer ¶
type HistorySummarizer interface {
// Summarize takes a list of messages and returns a summary result.
// If summarization is not needed, returns a result with KeepFromIndex = -1.
Summarize(ctx context.Context, msgIdToRunId map[string]string, messages []responses.InputMessageUnion, usage *responses.Usage) (*SummaryResult, error)
}
type NoOpExecutor ¶
type NoOpExecutor struct{}
NoOpExecutor is the default executor with no durability. It simply executes functions directly without checkpointing. Use this for existing behavior or when durability is not needed.
func NewNoOpExecutor ¶
func NewNoOpExecutor() *NoOpExecutor
NewNoOpExecutor creates a new no-op executor (existing behavior).
func (*NoOpExecutor) Checkpoint ¶
func (e *NoOpExecutor) Checkpoint(ctx context.Context, name string) error
Checkpoint is a no-op for the NoOpExecutor.
type RunState ¶
type RunState struct {
CurrentStep Step `json:"current_step"`
LoopIteration int `json:"loop_iteration"`
Usage responses.Usage `json:"usage"`
PendingToolCalls []responses.FunctionCallMessage `json:"pending_tool_calls,omitempty"`
ToolsAwaitingApproval []responses.FunctionCallMessage `json:"tools_awaiting_approval,omitempty"`
}
RunState encapsulates the execution state of an agent run
func LoadRunStateFromMeta ¶
LoadRunStateFromMeta loads RunState from messages.meta
func (*RunState) ClearPendingTools ¶
func (s *RunState) ClearPendingTools()
ClearPendingTools clears the pending tool calls
func (*RunState) HasToolsAwaitingApproval ¶
HasToolsAwaitingApproval returns true if there are tools waiting for approval
func (*RunState) IsComplete ¶
IsComplete returns true if the state is complete
func (*RunState) PromoteAwaitingToApproval ¶
func (s *RunState) PromoteAwaitingToApproval()
PromoteAwaitingToApproval moves tools awaiting approval to pending and transitions to await state
func (*RunState) TransitionToAwaitApproval ¶
func (s *RunState) TransitionToAwaitApproval(tools []responses.FunctionCallMessage)
TransitionToAwaitApproval moves to await approval step with the given tools
func (*RunState) TransitionToComplete ¶
func (s *RunState) TransitionToComplete()
TransitionToComplete moves to the complete step and clears pending tools
func (*RunState) TransitionToExecuteTools ¶
func (s *RunState) TransitionToExecuteTools(tools []responses.FunctionCallMessage)
TransitionToExecuteTools moves to tool execution step with the given tools
func (*RunState) TransitionToLLM ¶
func (s *RunState) TransitionToLLM()
TransitionToLLM moves to the LLM call step and increments loop iteration
type SummaryResult ¶
type SummaryResult struct {
Summary *responses.InputMessageUnion // The summary message
MessagesToKeep []responses.InputMessageUnion
LastSummarizedMessageID string // ID of the last message that was summarized
SummaryID string // Unique ID for the summary (generated if empty)
}
SummaryResult contains the result of summarization including metadata needed for saving