Documentation
¶
Overview ¶
Package executor provides the core execution engine for AI agent operations, implementing a robust system for running commands with support for streaming, tool calls, and asynchronous operations through a Future/Promise pattern.
Design decisions:
- Command pattern: Encapsulates execution parameters in RunCommand struct
- Future/Promise: Async operations with type-safe result handling
- Structured output: JSON Schema validation for responses
- Context awareness: All operations respect context cancellation
- Thread safety: Concurrent execution support with proper synchronization
- Flexible unmarshaling: Support for different response types (JSON, string, gjson)
Key components:
Executor: Interface defining the core execution contract ├── Run: Executes agent commands with streaming support └── handleToolCalls: Manages tool invocations during execution
RunCommand: Configuration for execution ├── Agent: The AI agent to execute ├── Thread: Memory aggregator for context ├── Stream: Enable/disable streaming mode └── Hook: Event handler for execution lifecycle
Future/Promise pattern: ├── CompletableFuture: Combined interface for async operations ├── Promise: Write interface for results └── Future: Read interface for retrieving results
Example usage:
// Create and configure a run command
cmd, err := NewRunCommand(agent, thread, hook)
if err != nil {
return err
}
cmd = cmd.WithStream(true).
WithMaxTurns(5).
WithContextVariables(vars)
// Create a future for the result
future := NewFuture(DefaultUnmarshal[MyResponse]())
// Execute the command
if err := executor.Run(ctx, cmd, future); err != nil {
return err
}
// Get the result (blocks until complete)
result, err := future.Get()
The package is designed to be internal, providing the execution engine while keeping implementation details private. It handles:
- Command execution lifecycle
- Asynchronous operation management
- Tool call coordination
- Response validation and unmarshaling
- Event distribution through hooks
- Context and cancellation management
Index ¶
- func DefaultUnmarshal[T any]() func([]byte) (T, error)
- func ToJSONSchema[T any]() *jsonschema.Schema
- type CompletableFuture
- type Executor
- type Future
- type Local
- type Promise
- type RunCommand
- func (r *RunCommand) ID() uuid.UUID
- func (r *RunCommand) Validate() error
- func (r RunCommand) WithContextVariables(contextVariables types.ContextVars) RunCommand
- func (r RunCommand) WithMaxTurns(maxTurns int) RunCommand
- func (r RunCommand) WithResponseSchema(schema *jsonschema.Schema) RunCommand
- func (r RunCommand) WithStream(stream bool) RunCommand
- type Temporal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUnmarshal ¶ added in v0.1.0
func ToJSONSchema ¶ added in v0.1.0
func ToJSONSchema[T any]() *jsonschema.Schema
Types ¶
type CompletableFuture ¶ added in v0.1.0
type Executor ¶
type Executor interface {
Run(context.Context, RunCommand, Promise) error
// contains filtered or unexported methods
}
type RunCommand ¶
type RunCommand struct {
Agent api.Owl
Thread *shorttermmemory.Aggregator
ResponseSchema *jsonschema.Schema
Stream bool
MaxTurns int
ContextVariables types.ContextVars
Hook events.Hook
// contains filtered or unexported fields
}
func NewRunCommand ¶
func NewRunCommand(agent api.Owl, thread *shorttermmemory.Aggregator, hook events.Hook) (RunCommand, error)
func (*RunCommand) ID ¶
func (r *RunCommand) ID() uuid.UUID
func (*RunCommand) Validate ¶ added in v0.1.0
func (r *RunCommand) Validate() error
func (RunCommand) WithContextVariables ¶
func (r RunCommand) WithContextVariables(contextVariables types.ContextVars) RunCommand
func (RunCommand) WithMaxTurns ¶
func (r RunCommand) WithMaxTurns(maxTurns int) RunCommand
func (RunCommand) WithResponseSchema ¶ added in v0.1.1
func (r RunCommand) WithResponseSchema(schema *jsonschema.Schema) RunCommand
func (RunCommand) WithStream ¶
func (r RunCommand) WithStream(stream bool) RunCommand