Documentation
¶
Index ¶
- Constants
- func DecodeMessage[T any](msg ChatCompletionResponse) (T, error)
- func NewRuntime(opts ...RuntimeOption) *runtime
- type Agent
- type AgentChoiceEvent
- type AgentDef
- type AgentOption
- type AgentReasoningEvent
- type Agents
- type ChatCompletionChunk
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatMessage
- type CompletionTokenDetails
- type CostDetails
- type DebugContextKey
- type ErrorEvent
- type EventKind
- type ExecuteFunc
- type FinalEvent
- type JSONSchema
- type LLMProvider
- type Message
- type OpenRouterProvider
- type OrchestrationFile
- type Plan
- type PlanResultEvent
- type PromptTokenDetails
- type RemoteToolset
- type ResponseFormat
- type ResponseFormatType
- type ResponseOption
- type Runtime
- type RuntimeEvent
- type RuntimeOption
- type Session
- type SessionDef
- type Tool
- type ToolErrorEvent
- type ToolResultEvent
- type Tools
- type Toolset
- type TransferAgentEvent
- type Usage
Constants ¶
const ( ResponseFormatTypeJSON = "json_object" ResponseFormatTypeJSONSchema = "json_schema" ResponseFormatTypeText = "text" )
const AgentModeLoop = "loop"
const AgentModePlan = "plan"
const AgentModeSingle = "single"
const ChatMessageRoleAssistant = "assistant"
const ChatMessageRoleFunction = "function"
const ChatMessageRoleSystem = "system"
const ChatMessageRoleTool = "tool"
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 ¶
ExecuteTool executes a tool by ID with the given parameters
func (*Agent) Step ¶
func (t *Agent) Step(ctx context.Context, args map[string]any, opts ...ResponseOption) (ChatCompletionResponse, error)
Non-streaming completion
type AgentChoiceEvent ¶
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 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 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 ¶
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 ErrorEvent ¶
type FinalEvent ¶
type FinalEvent struct {
Output string `json:"output"`
}
type JSONSchema ¶
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 OpenRouterProvider ¶
type OpenRouterProvider struct {
// contains filtered or unexported fields
}
func NewOpenRouterProvider ¶
func NewOpenRouterProvider(client *openrouter.Client) *OpenRouterProvider
func (*OpenRouterProvider) ChatCompletion ¶
func (p *OpenRouterProvider) ChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error)
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 PlanResultEvent ¶
type PlanResultEvent struct {
Plans []Plan `json:"plans"`
}
type PromptTokenDetails ¶
type PromptTokenDetails struct {
CachedTokens int `json:"cached_tokens"`
}
type RemoteToolset ¶
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 ¶
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 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"`
}
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 ToolResultEvent ¶
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.