Files
archie/internal/domain/curator/registrar.go
T

172 lines
5.9 KiB
Go

package curator
import (
"context"
"log/slog"
"time"
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
"github.com/samcharles93/archie-core/internal/tools"
)
// Registrar is the host access a curator receives, limited to what its
// manifest declares.
type Registrar struct {
// Log is the curator-scoped diagnostic logger. It is optional so domain
// tests and embedders can construct a registrar without a logging sink.
Log *slog.Logger
// Model is the default model reference ("provider/model") for
// curators whose manifest leaves Model empty.
Model string
// LLM provides model access for agentic passes. Bound when the curator
// declares an agentic capability (tools, skills, or a memory engine).
LLM LLMRunner
// Tools resolves the declared tool names into a runnable tool set.
// Resolution is the enforcement point: a pass receives exactly the
// declared set, never a broader registry. Bound when tools are
// declared.
Tools ToolBuilder
// Skills is the skill-maintenance capability. Bound when the curator
// declares Skills.
Skills SkillStore
// MemoryEngines resolves a memory engine by name. Bound only when the
// manifest declares one.
MemoryEngines MemoryEngineSource
// Conversations is read-only recent conversation history, for a curator
// that declared Manifest.Conversations. Bound only when declared.
Conversations ConversationSource
// Events publishes curator activity. Implementations must be
// non-blocking and bounded (drop on overflow), so a curator can never
// apply backpressure to a chat turn or the daemon. Always bound.
Events EventSink
// Clock is injectable time. Always bound; nil at construction is
// replaced with the system clock.
Clock Clock
}
// LLMRunner is the model access a curator needs for a pass. The app layer
// adapts the shared runtime to this narrow contract.
type LLMRunner interface {
Chat(ctx context.Context, req ChatRequest) (ChatResult, error)
}
// ChatRequest is one model call: messages plus the runnable tool set.
type ChatRequest struct {
Model string
Messages []Message
Tools []tools.ToolEntry
MaxSteps int
}
// Message is one conversation message.
type Message struct {
Role string // e.g. "system", "user", "assistant", "tool"
Content string
}
// ChatResult is the model's final answer plus the tool invocations the
// model loop executed, so a pass can attribute its actions to the tools
// that ran.
type ChatResult struct {
Text string
// ToolCalls is every tool invocation across the loop, in execution
// order. Empty for a single completion with no tools.
ToolCalls []ToolCall
}
// ToolCall is one tool invocation the model loop executed.
type ToolCall struct {
Name string
Input string // JSON-encoded arguments, verbatim from the model
}
// ToolBuilder resolves declared tool names into a runnable tool set. A
// declared name with no implementation fails the pass rather than silently
// running with fewer tools, and no tool outside the declared set is
// returned.
type ToolBuilder interface {
Build(ctx context.Context, declared []string) ([]tools.ToolEntry, error)
}
// SkillStore is the skill-maintenance capability. The implementation owns
// the on-disk format and catalog reload rules.
type SkillStore interface {
List(ctx context.Context) ([]SkillRef, error)
Read(ctx context.Context, name string) (Skill, error)
Write(ctx context.Context, s Skill) error
Delete(ctx context.Context, name string) error
}
// SkillRef identifies one skill on disk.
type SkillRef struct {
Name string
Path string
}
// Skill is one skill definition.
type Skill struct {
Name string
Content string
Description string
}
// MemoryEngineSource resolves a named memory engine. Mirrors
// domain/memory.Registry.Get's exact signature so the real registry
// satisfies this without an adapter, while this package stays decoupled
// from that package's concrete Registry type.
type MemoryEngineSource interface {
Get(name string) (domainmemory.MemoryEngine, bool)
}
// ConversationSource is read-only conversation history, narrowed to what
// a curator needs to review recent activity -- never the full session
// CRUD/branch/search surface a chat gateway exposes. The app layer adapts
// the real session store to this.
type ConversationSource interface {
// RecentSessions returns every session touched at or after since,
// newest first.
RecentSessions(ctx context.Context, since time.Time) ([]SessionSummary, error)
// Messages returns the most recent n messages of one session, in
// chronological order.
Messages(ctx context.Context, sessionID string, n int) ([]ConversationMessage, error)
}
// SessionSummary identifies one session, the agent that served it, and when
// it was last active.
type SessionSummary struct {
ID string
// AgentID is the agent that owns the session, as recorded on the
// session's own source. Agent-user memory is addressed by it, so a
// curator never has to recover the agent from the session id.
AgentID string
LastActive time.Time
}
// ConversationMessage is one message in a session's history.
type ConversationMessage struct {
Role string // "user" or "assistant"
Content string
// SenderID is the sender's channel-native ID, empty for assistant messages.
SenderID string
At time.Time
}
// EventSink publishes curator activity (what ran, what changed, why). It is
// the emission side only; wake signals arrive through the runtime's own
// subscription. Implementations MUST be non-blocking and
// bounded, matching the in-process event bus semantics.
type EventSink interface {
Emit(kind, detail string, data map[string]any)
}
// Clock is injectable time: Now for timestamps and After for loop sleeps.
type Clock interface {
Now() time.Time
After(d time.Duration) <-chan time.Time
}
type systemClock struct{}
func (systemClock) Now() time.Time { return time.Now() }
func (systemClock) After(d time.Duration) <-chan time.Time { return time.After(d) }