clearcast

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

README

clearcast

LLM prompting as golang txt/template as its engine

Documentation

Index

Constants

View Source
const (
	ResponseFormatTypeJSON       = "json_object"
	ResponseFormatTypeJSONSchema = "json_schema"
	ResponseFormatTypeText       = "text"
)
View Source
const AgentModeLoop = "loop"
View Source
const AgentModePlan = "plan"
View Source
const AgentModeSingle = "single"
View Source
const ChatMessageRoleAssistant = "assistant"
View Source
const ChatMessageRoleFunction = "function"
View Source
const ChatMessageRoleSystem = "system"
View Source
const ChatMessageRoleTool = "tool"
View Source
const ChatMessageRoleUser = "user"

Variables

This section is empty.

Functions

func DecodeMessage

func DecodeMessage[T any](msg ChatCompletionResponse) (T, error)

func NewRuntime

func NewRuntime(opts ...RuntimeOption) *runtime

Types

type Agent

type Agent struct {
	ID        string
	Prompt    string
	Iteration int
	Model     string
	// contains filtered or unexported fields
}

Agent struct with slog and OTEL toggle

func NewAgent

func NewAgent(id, model, prompt string, llm LLMProvider, opts ...AgentOption) *Agent

NewAgent creates a new Prompt with slog (JSON handler) and OTEL enabled by default

func (*Agent) ExecuteTool

func (a *Agent) ExecuteTool(ctx context.Context, toolID string, params map[string]any) (any, error)

ExecuteTool executes a tool by ID with the given parameters

func (*Agent) GetTools

func (a *Agent) GetTools() Tools

GetTools returns the agent's tools

func (*Agent) Step

func (t *Agent) Step(ctx context.Context, args map[string]any, opts ...ResponseOption) (ChatCompletionResponse, error)

Non-streaming completion

type AgentChoiceEvent

type AgentChoiceEvent struct {
	Content string `json:"content"`
	Usage   Usage  `json:"usage"`
}

type AgentDef

type AgentDef struct {
	ID       string    `yaml:"id"`
	Mode     string    `yaml:"mode"`
	Model    string    `yaml:"model"`
	Prompt   string    `yaml:"prompt"`
	Toolsets []Toolset `yaml:"toolsets,omitempty"` // Tools specific to this agent
}

AgentDef defines the structure for an agent in the YAML configuration.

type AgentOption

type AgentOption func(*Agent)

AgentOption defines a functional option for configuring Prompt

func WithDefaultTools

func WithDefaultTools(IDs ...string) AgentOption

func WithOTEL

func WithOTEL(enabled bool) AgentOption

WithOTEL enables or disables OTEL tracing

func WithSlogLogger

func WithSlogLogger(logger *slog.Logger) AgentOption

WithSlogLogger sets the slog.Logger for Prompt

func WithTool

func WithTool(tool *Tool) AgentOption

func WithTools

func WithTools(tools ...*Tool) AgentOption

type AgentReasoningEvent

type AgentReasoningEvent struct {
	Content string `json:"content"`
	Usage   Usage  `json:"usage"`
}

type Agents

type Agents map[string]*Agent

type ChatCompletionChunk

type ChatCompletionChunk struct {
	Delta string // partial text delta
	Done  bool
	Raw   any
	Usage Usage
}

ChatCompletionChunk is a streamed chunk of a completion.

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model          string
	Messages       []ChatMessage
	Options        map[string]any
	ResponseFormat *ResponseFormat
}

ChatCompletionRequest is a provider-neutral request type.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Content string
	Raw     any // keep raw provider response if needed
	Usage   Usage
}

ChatCompletionResponse represents a full completion result.

type ChatMessage

type ChatMessage struct {
	Role    string
	Content string
}

ChatMessage is a message in a chat conversation.

func AssistantMessage

func AssistantMessage(content string) ChatMessage

func FunctionMessage

func FunctionMessage(callID string, content string) ChatMessage

func SystemMessage

func SystemMessage(content string) ChatMessage

func ToolMessage

func ToolMessage(callID string, content string) ChatMessage

func UserMessage

func UserMessage(content string) ChatMessage

type CompletionTokenDetails

type CompletionTokenDetails struct {
	ReasoningTokens int `json:"reasoning_tokens"`
}

type CostDetails

type CostDetails struct {
	UpstreamInferenceCost float64 `json:"upstream_inference_cost"`
}

type DebugContextKey

type DebugContextKey struct{}

DebugContextKey for context-based debug flag

type ErrorEvent

type ErrorEvent struct {
	Type  string `json:"type"`
	Error string `json:"error"`
}

type EventKind

type EventKind string

type ExecuteFunc

type ExecuteFunc func(ctx context.Context, params map[string]any) (any, error)

type FinalEvent

type FinalEvent struct {
	Output string `json:"output"`
}

type JSONSchema

type JSONSchema struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Schema      json.Marshaler `json:"schema"`
	Strict      bool           `json:"strict"`
}

type LLMProvider

type LLMProvider interface {
	ChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error)
	ChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (<-chan ChatCompletionChunk, error)
}

LLMProvider defines the minimal interface for any chat LLM backend.

type Message

type Message struct {
	Role    string
	Content string
	// Summaryy is the summary of all the messages up to this point, act as a compaction
	Summary string
}

type OpenRouterProvider

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

func NewOpenRouterProvider

func NewOpenRouterProvider(client *openrouter.Client) *OpenRouterProvider

func (*OpenRouterProvider) ChatCompletion

func (*OpenRouterProvider) ChatCompletionStream

func (p *OpenRouterProvider) ChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (<-chan ChatCompletionChunk, error)

type OrchestrationFile

type OrchestrationFile struct {
	Agents  []AgentDef `yaml:"agents"`
	Session SessionDef `yaml:"session"`
}

OrchestrationFile defines the top-level structure of the YAML file.

type Plan

type Plan struct {
	// Kind can be either "tool" or "agent"
	// Kind   string         `json:"kind"`
	Tool   string         `json:"tool"`
	Params map[string]any `json:"params"`
}

type PlanResultEvent

type PlanResultEvent struct {
	Plans []Plan `json:"plans"`
}

type PromptTokenDetails

type PromptTokenDetails struct {
	CachedTokens int `json:"cached_tokens"`
}

type RemoteToolset

type RemoteToolset struct {
	URL           string `yaml:"url"`
	TransportType string `yaml:"transport_type"`
}

type ResponseFormat

type ResponseFormat struct {
	Type       ResponseFormatType
	JSONSchema *JSONSchema
}

type ResponseFormatType

type ResponseFormatType string

type ResponseOption

type ResponseOption func(*ChatCompletionRequest)

func WithResponseFormat

func WithResponseFormat(format ResponseFormat) ResponseOption

type Runtime

type Runtime interface {
	Run(ctx context.Context) (string, error)
	RunStream(ctx context.Context) <-chan RuntimeEvent
}

Runtime is an execution environment that can run tasks (agents or plain functions)

func NewRunFromPath

func NewRunFromPath(yamlFilepath string) (Runtime, error)

NewRunFromPath creates a new runtime from a config file (yaml)

type RuntimeEvent

type RuntimeEvent interface {
	// contains filtered or unexported methods
}

RuntimeEvent is an event that is emitted by the runtime It could be either an error, tool execution result, agent transfer or final output

func Error

func Error(msg string) RuntimeEvent

func Final

func Final(output string) RuntimeEvent

func PlanResult

func PlanResult(plan []Plan) RuntimeEvent

func ToolError

func ToolError(tool string, params any, err error) RuntimeEvent

func ToolResult

func ToolResult(key string, result any) RuntimeEvent

func TransferAgent

func TransferAgent(agentID string) RuntimeEvent

type RuntimeOption

type RuntimeOption func(*runtime)

func WithAgents

func WithAgents(agents ...*Agent) RuntimeOption

func WithSession

func WithSession(sess *Session) RuntimeOption

type Session

type Session struct {
	RootAgentID   string         `json:"root_agent_id"`
	Workspace     map[string]any `json:"workspace"`
	Mission       string         `json:"mission"`
	Memory        map[string]any `json:"memory"`
	Messages      []Message      `json:"messages"`
	CreatedAt     time.Time      `json:"created_at"`
	MaxIterations int            `json:"max_iterations"`

	InputTokens  int     `json:"input_tokens"`
	OutputTokens int     `json:"output_tokens"`
	Cost         float64 `json:"cost"`
	Tools        []*Tool `json:"tools"`
}

func (*Session) ToMap

func (s *Session) ToMap() map[string]any

to map[string]any

type SessionDef

type SessionDef struct {
	RootAgentID string         `yaml:"root_agent_id"`
	Extra       map[string]any `yaml:",inline"` // Captures all other fields like topic, etc.

}

SessionDef defines the structure for the session in the YAML configuration.

type Tool

type Tool struct {
	ID          string      `json:"id"`
	Description string      `json:"description"`
	Execute     ExecuteFunc `json:"execute"`
	Usage       string      `json:"usage"`
}

func WebSearchTool

func WebSearchTool() *Tool

WebSearchTool creates a new tool for interacting with the Serper.dev API.

type ToolErrorEvent

type ToolErrorEvent struct {
	Tool   string `json:"tool"`
	Error  string `json:"error"`
	Params any    `json:"params"`
}

type ToolResultEvent

type ToolResultEvent struct {
	Tool   string `json:"tool"`
	Result any    `json:"result"`
	Error  string `json:"error"`
}

type Tools

type Tools map[string]*Tool

func (Tools) Execute

func (t Tools) Execute(ctx context.Context, toolID string, params map[string]any) (any, error)

type Toolset

type Toolset struct {
	Type        string         `yaml:"type"`
	ID          string         `yaml:"id"`
	Remote      *RemoteToolset `yaml:"remote,omitempty"`
	Prompt      string         `yaml:"prompt,omitempty"`
	Description string         `yaml:"description,omitempty"`
	Model       string         `yaml:"model,omitempty"`
}

type TransferAgentEvent

type TransferAgentEvent struct {
	AgentID string `json:"agent_id"`
}

type Usage

type Usage struct {
	PromptTokens           int                    `json:"prompt_tokens"`
	CompletionTokens       int                    `json:"completion_tokens"`
	CompletionTokenDetails CompletionTokenDetails `json:"completion_token_details"`
	TotalTokens            int                    `json:"total_tokens"`
	Cost                   float64                `json:"cost"`
	CostDetails            CostDetails            `json:"cost_details"`
	PromptTokenDetails     PromptTokenDetails     `json:"prompt_token_details"`
}

Usage Represents the total token usage per request.

Jump to

Keyboard shortcuts

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