api

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent added in v0.1.3

type Agent interface {
	// Name returns the agent's unique identifier.
	// This name should be consistent across sessions and is used for logging,
	// debugging, and distinguishing between multiple agents in the system.
	Name() string

	// Model returns the configuration and capabilities of the underlying AI model.
	// This includes model-specific settings, limitations, and supported features
	// that affect how the agent operates.
	Model() Model

	// Tools returns the set of functions this agent can execute.
	// These definitions describe the available tools, their parameters,
	// and how they should be invoked. The agent uses these definitions
	// to understand its capabilities and make informed decisions.
	Tools() []tool.Definition

	// ParallelToolCalls indicates if this agent can execute multiple tools concurrently.
	// When true, the agent may batch compatible tool calls together for improved performance.
	// This is particularly useful for I/O-bound operations or independent tasks.
	ParallelToolCalls() bool

	// RenderInstructions generates the agent's operational instructions using the provided context.
	// The context variables allow for dynamic customization of the agent's behavior
	// based on runtime conditions, user preferences, or system state.
	//
	// Returns an error if the instructions cannot be rendered with the given context,
	// for example if required variables are missing or template syntax is invalid.
	RenderInstructions(types.ContextVars) (string, error)

	Instructions() string
}

Agent represents the core interface for AI agents in the system. It defines the essential capabilities and configuration options that every agent must implement.

Design decisions:

  • Minimal interface: Only includes essential methods needed for agent operation
  • Immutable configuration: Methods return values rather than allowing runtime changes
  • Flexible instruction rendering: Supports dynamic instructions based on context
  • Optional parallel execution: Agents can opt-in to parallel tool execution

Example usage:

agent := NewAgent(config)
if agent.ParallelToolCalls() {
    // Handle parallel tool execution
}
instructions, err := agent.RenderInstructions(contextVars)
if err != nil {
    // Handle error
}

The interface is designed to be implementation-agnostic, allowing different types of agents (e.g., local models, API-based services) to provide these capabilities while maintaining a consistent integration surface.

type Model

type Model interface {
	// Name returns the identifier for this model as expected by the provider.
	// For example, with OpenAI this might be "gpt-4" or "gpt-3.5-turbo".
	// The name should be consistent with what the provider's API expects.
	Name() string

	// Provider returns the provider implementation that can execute requests
	// for this model. The provider handles the actual communication with
	// the AI service (e.g., OpenAI, Anthropic).
	//
	// The returned provider must be safe for concurrent use, as it may be
	// accessed by multiple goroutines simultaneously.
	Provider() provider.Provider
}

Model defines the interface that all AI models must implement. It serves as a bridge between the model's identity and its provider implementation, allowing for a clean separation between model configuration and provider functionality.

The interface is intentionally minimal to make it easy to implement while providing all necessary information for the system to work with different models.

type RunResult added in v0.1.0

type RunResult[T any] struct {
	Success T
	Err     error
}

func (RunResult[T]) IsError added in v0.1.0

func (r RunResult[T]) IsError() bool

func (RunResult[T]) IsSuccess added in v0.1.0

func (r RunResult[T]) IsSuccess() bool

Jump to

Keyboard shortcuts

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