Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT Purpose: Agent abstraction + mock implementation. Real LLM-backed implementations would call a model API; for now, agents can be run in "mock" mode that produces deterministic placeholder output (useful for testing the dispatcher, planner, and aggregator in isolation).
SPDX-License-Identifier: MIT Purpose: aggregator — combines sub-task results into a final response for the user. Validates success, formats output.
SPDX-License-Identifier: MIT Purpose: dispatcher — runs plan tasks in parallel with dependency-aware scheduling. Tasks whose DependsOn are still running block until those complete. Results are merged into a shared scratchpad.
SPDX-License-Identifier: MIT Purpose: small helpers shared across orchestrator files.
SPDX-License-Identifier: MIT Purpose: orchestrator data model — Plan, Task, Agent, Result, ScratchpadEntry.
SPDX-License-Identifier: MIT Purpose: LLMAgent — provider-agnostic LLM-backed agent. Uses the Provider field in AgentConfig to pick a backend (nim, openai, anthropic, ollama, groq, custom). Backwards-compatible: NIMAgent is a thin wrapper.
SPDX-License-Identifier: MIT Purpose: top-level Orchestrator — wires together Router, Planner, Dispatcher, Registry, Scratchpad, Aggregator. This is the main entry point.
SPDX-License-Identifier: MIT Purpose: planner — turns a user prompt + classified intent into a Plan with ordered sub-tasks, each bound to a specialized agent.
SPDX-License-Identifier: MIT Purpose: agent registry — loads default agents, merges user agents from ~/.config/sin-code/agents/{name}/agent.toml, picks the right agent for a task type. Uses NIMAgent when SIN_NIM_API_KEY is set, MockAgent otherwise.
SPDX-License-Identifier: MIT Purpose: Pre-LLM router — cheap intent classification using keyword heuristics. In production, this would call a Haiku-class model. For now, deterministic keyword scoring is the fallback when no LLM is configured.
Index ¶
- func DefaultUserAgentsPath() string
- func GenerateID(prefix string) string
- func UseLLM() bool
- func UseNIM() bool
- type Agent
- type AgentConfig
- type Aggregator
- type Dispatcher
- type Intent
- type LLMAgent
- type MockAgent
- type NIMAgent
- type Orchestrator
- type Plan
- type Planner
- type Registry
- type Result
- type Router
- type RunOption
- type Scratchpad
- type ScratchpadEntry
- type Task
- type TaskStatus
- type TaskType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUserAgentsPath ¶
func DefaultUserAgentsPath() string
func GenerateID ¶
Types ¶
type Agent ¶
type Agent interface {
Name() string
Config() AgentConfig
Run(ctx context.Context, task *Task, scratch *Scratchpad) (string, error)
}
type AgentConfig ¶
type AgentConfig struct {
Name string `toml:"name"`
Description string `toml:"description"`
Type TaskType `toml:"type"`
Provider string `toml:"provider"`
BaseURL string `toml:"base_url"`
Model string `toml:"model"`
MaxTokens int `toml:"max_tokens"`
Temperature float64 `toml:"temperature"`
SystemFile string `toml:"system_file"`
MaxContext int `toml:"max_context_tokens"`
ToolsAllow []string `toml:"tools_allow"`
ToolsDeny []string `toml:"tools_deny"`
MemoryNS string `toml:"memory_namespace"`
RetentionDays int `toml:"retention_days"`
}
func DefaultAgents ¶
func DefaultAgents() []AgentConfig
func LoadUserAgents ¶
func LoadUserAgents(baseDir string) ([]AgentConfig, error)
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
func NewAggregator ¶
func NewAggregator(scratch *Scratchpad) *Aggregator
func (*Aggregator) Aggregate ¶
func (a *Aggregator) Aggregate(plan *Plan) *Result
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func NewDispatcher(registry *Registry, scratch *Scratchpad, maxParallel int) *Dispatcher
type LLMAgent ¶
type LLMAgent struct {
// contains filtered or unexported fields
}
func NewLLMAgent ¶
func NewLLMAgent(cfg AgentConfig) *LLMAgent
func NewLLMAgentWithClient ¶
func NewLLMAgentWithClient(cfg AgentConfig, client *llm.Client) *LLMAgent
func (*LLMAgent) Config ¶
func (a *LLMAgent) Config() AgentConfig
type MockAgent ¶
type MockAgent struct {
// contains filtered or unexported fields
}
func NewMockAgent ¶
func NewMockAgent(cfg AgentConfig) *MockAgent
func (*MockAgent) Config ¶
func (m *MockAgent) Config() AgentConfig
type NIMAgent ¶
type NIMAgent = LLMAgent
Backwards-compat alias.
func NewNIMAgent ¶
func NewNIMAgent(cfg AgentConfig) *NIMAgent
func NewNIMAgentWithClient ¶
func NewNIMAgentWithClient(cfg AgentConfig, client *llm.Client) *NIMAgent
type Orchestrator ¶
type Orchestrator struct {
Registry *Registry
Planner *Planner
Dispatcher *Dispatcher
Aggregator *Aggregator
Scratchpad *Scratchpad
MaxParallel int
}
func New ¶
func New() *Orchestrator
func NewWithAgents ¶
func NewWithAgents(extraConfigs []AgentConfig) *Orchestrator
func (*Orchestrator) Plan ¶
func (o *Orchestrator) Plan(prompt string) *Plan
func (*Orchestrator) String ¶
func (o *Orchestrator) String() string
type Plan ¶
type Plan struct {
ID string `json:"id"`
Prompt string `json:"prompt"`
Intent Intent `json:"intent"`
Tasks []*Task `json:"tasks"`
Created time.Time `json:"created"`
Started time.Time `json:"started"`
Completed time.Time `json:"completed"`
TotalCost float64 `json:"total_cost"`
TokensUsed int `json:"tokens_used"`
Success bool `json:"success"`
}
type Planner ¶
type Planner struct {
Router *Router
Agents []AgentConfig
}
func NewPlanner ¶
func NewPlanner(agents []AgentConfig) *Planner
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistryWithDefaults ¶
func NewRegistryWithDefaults(extraConfigs []AgentConfig) *Registry
func (*Registry) List ¶
func (r *Registry) List() []AgentConfig
type Router ¶
func (*Router) SubIntents ¶
type Scratchpad ¶
type Scratchpad struct {
// contains filtered or unexported fields
}
func NewScratchpad ¶
func NewScratchpad() *Scratchpad
func (*Scratchpad) Merge ¶
func (s *Scratchpad) Merge(other *Scratchpad)
func (*Scratchpad) ReadAll ¶
func (s *Scratchpad) ReadAll() map[string]*ScratchpadEntry
func (*Scratchpad) Write ¶
func (s *Scratchpad) Write(agent, section, content string)
type ScratchpadEntry ¶
type Task ¶
type Task struct {
ID string `json:"id"`
Type TaskType `json:"type"`
Description string `json:"description"`
AgentName string `json:"agent"`
DependsOn []string `json:"depends_on,omitempty"`
Status TaskStatus `json:"status"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
Created time.Time `json:"created"`
Started *time.Time `json:"started,omitempty"`
Completed *time.Time `json:"completed,omitempty"`
TokensUsed int `json:"tokens_used"`
Cost float64 `json:"cost"`
}
type TaskStatus ¶
type TaskStatus string
const ( TaskPending TaskStatus = "pending" TaskRunning TaskStatus = "running" TaskCompleted TaskStatus = "completed" TaskFailed TaskStatus = "failed" TaskCancelled TaskStatus = "cancelled" TaskBlocked TaskStatus = "blocked" )