Documentation
¶
Overview ¶
Package intent provides a goal-driven agent framework built on RonyKit.
An Agent wraps a rony.Server and composes knowledge, LLM pools, memory, MCP servers, and rony endpoints. Agents expose HTTP/RPC handlers through ServiceDescriptor and EndpointMount without passing *rony.Server to user code.
Core types ¶
All agent building blocks live in this package:
- Embedder — vector embedding for memory and RAG backends
- Knowledge, StaticStore, Retriever, Indexer — static catalog and RAG
- LLM, Pool, Selector — language model backends and selection
- Memory, SessionMemory — session-scoped conversation state
- MCPServer, MCPRegistry — external MCP tool and context sources
- LocalTool, ToolRegistry — local and MCP-backed executable tools
- Skill, SkillRegistry — on-demand capabilities loaded via activate_skill
- Agent — entry point for turns, sessions, and server lifecycle
- ServiceDescriptor, EndpointMount, ServiceRegistry — rony endpoints
- TaskExecutor, TaskHandle, TaskState — durable task lifecycle
Subpackages:
- intent/errs — shared error sentinels
Index ¶
- Constants
- func AppendHistory(ctx context.Context, s *Session, msgs ...Message) error
- func FormatSkillCatalog(cards []SkillCard) string
- func SaveHistory(ctx context.Context, s *Session, msgs []Message) error
- func Setup[S rony.State[A], A rony.Action](m EndpointMount, serviceName string, init rony.InitState[S, A], ...)
- type Agent
- func (a *Agent) Config() Config
- func (a *Agent) ExportDesc() []desc.ServiceDesc
- func (a *Agent) PrintRoutes(w io.Writer)
- func (a *Agent) Run(ctx context.Context, signals ...os.Signal) error
- func (a *Agent) RunTurn(ctx context.Context, in TurnInput) (TurnResult, error)
- func (a *Agent) Server() *rony.Server
- func (a *Agent) Sessions() *SessionManager
- func (a *Agent) Start(ctx context.Context) error
- func (a *Agent) Stop(ctx context.Context, signals ...os.Signal)
- type Choice
- type Chunk
- type Config
- type DefaultLLMPool
- type DefaultSkillRegistry
- type DefaultToolRegistry
- func (r *DefaultToolRegistry) Definitions(ctx context.Context) ([]ToolDefinition, error)
- func (r *DefaultToolRegistry) Execute(ctx context.Context, call ToolCall) (Message, error)
- func (r *DefaultToolRegistry) Register(t LocalTool) error
- func (r *DefaultToolRegistry) RegisterMCP(server MCPServer) error
- type Document
- type Embedder
- type EndpointMount
- type Entry
- type Filter
- type GenerateOptions
- type Indexer
- type Kind
- type Knowledge
- type LLM
- func ByPriority(models []LLM) []LLM
- func Select(ctx context.Context, models []LLM, sel Selection) (LLM, error)
- func SelectEnforced(_ context.Context, models []LLM, sel Selection) (LLM, error)
- func SelectFirst(_ context.Context, models []LLM, _ Selection) (LLM, error)
- func SelectPriority(_ context.Context, models []LLM, _ Selection) (LLM, error)
- func SelectRandom(_ context.Context, models []LLM, _ Selection) (LLM, error)
- type LocalTool
- type LocalToolFunc
- type MCPClientFactory
- type MCPContentBlock
- type MCPPromptMessage
- type MCPPromptResult
- type MCPPromptSummary
- type MCPRegistry
- type MCPResourceContent
- type MCPResourceSummary
- type MCPServer
- type MCPServerConfig
- type MCPTool
- type MCPToolResult
- type MCPTransportKind
- type MapServiceRegistry
- type Memory
- type MemoryQuery
- type MemoryRecord
- type MemoryResult
- type Message
- type Model
- type Option
- func WithExecutor(exec TaskExecutor) Option
- func WithKnowledge(k Knowledge) Option
- func WithLLMPool(pool Pool) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMCPServers(reg MCPRegistry) Option
- func WithMaxToolIterations(limit int) Option
- func WithMemory(m Memory) Option
- func WithName(name string) Option
- func WithRetriever(retriever Retriever) Option
- func WithServer(srv *rony.Server) Option
- func WithServerOption(opts ...rony.ServerOption) Option
- func WithService(desc ServiceDescriptor) Option
- func WithServiceRegistry(reg ServiceRegistry) Option
- func WithSessions(mgr *SessionManager) Option
- func WithSkills(reg SkillRegistry) Option
- func WithStaticKnowledge(store StaticStore) Option
- func WithTools(reg ToolRegistry) Option
- type Origin
- type Part
- type Pool
- type Request
- type Response
- type RetrieveQuery
- type Retriever
- type Role
- type Selection
- type Selector
- type SelectorFunc
- type ServiceDescriptor
- type ServiceRegistry
- type Session
- type SessionManager
- type SessionMemory
- type SessionOption
- type Skill
- type SkillCard
- type SkillRegistry
- type StaticStore
- type Strategy
- type Stream
- type TaskExecutor
- type TaskHandle
- type TaskState
- type ToolCall
- type ToolDefinition
- type ToolExecutor
- type ToolRegistry
- type TurnInput
- type TurnResult
Constants ¶
const ActivateSkillTool = "activate_skill"
ActivateSkillTool is the reserved name of the synthetic tool the runtime advertises so the model can load a skill's full instructions on demand.
const SkillCatalogTitle = prompt.SkillCatalogTitle
SkillCatalogTitle is the heading injected with the per-turn skill catalog.
Variables ¶
This section is empty.
Functions ¶
func AppendHistory ¶
AppendHistory appends messages to stored session history.
func FormatSkillCatalog ¶
FormatSkillCatalog renders the advertised skill routing guide.
func SaveHistory ¶
SaveHistory replaces the stored conversation history for the session.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent wraps a rony.Server with agent capabilities: knowledge, LLMs, memory, MCP servers, and rony endpoints. Agent is the public entry point for running turns and serving endpoints.
func (*Agent) ExportDesc ¶
func (a *Agent) ExportDesc() []desc.ServiceDesc
ExportDesc returns service descriptions from the underlying server.
func (*Agent) PrintRoutes ¶
PrintRoutes writes registered routes to w.
func (*Agent) Sessions ¶
func (a *Agent) Sessions() *SessionManager
Sessions returns the configured session manager, if any.
type Choice ¶
type Choice struct {
Content string
ToolCalls []ToolCall
FinishReason string
ReasoningContent string
GenerationInfo map[string]any
}
Choice is one completion candidate.
type Chunk ¶
type Chunk struct {
Content string
ReasoningContent string
ToolCalls []ToolCall
FinishReason string
Done bool
}
Chunk is one streaming update.
type Config ¶
type Config struct {
Name string
Knowledge Knowledge
StaticKnowledge StaticStore
Retriever Retriever
LLM Pool
Memory Memory
MCPServers MCPRegistry
Tools ToolRegistry
Skills SkillRegistry
Sessions *SessionManager
Services ServiceRegistry
Executor TaskExecutor
}
Config exposes the agent's composed dependencies.
type DefaultLLMPool ¶
type DefaultLLMPool struct {
// contains filtered or unexported fields
}
DefaultLLMPool is a Pool backed by a Selector.
func NewLLMPool ¶
func NewLLMPool(models []LLM, selector Selector) (*DefaultLLMPool, error)
NewLLMPool returns a pool with the given models and selector. When the selector is nil, StrategyFirst is used.
func (*DefaultLLMPool) Models ¶
func (p *DefaultLLMPool) Models() []Model
type DefaultSkillRegistry ¶
type DefaultSkillRegistry struct {
// contains filtered or unexported fields
}
DefaultSkillRegistry is an in-memory SkillRegistry.
func NewSkillRegistry ¶
func NewSkillRegistry() *DefaultSkillRegistry
NewSkillRegistry returns an empty in-memory skill registry.
func (*DefaultSkillRegistry) List ¶
func (r *DefaultSkillRegistry) List(_ context.Context) ([]SkillCard, error)
func (*DefaultSkillRegistry) Register ¶
func (r *DefaultSkillRegistry) Register(skill Skill) error
Register adds a skill to the registry. The skill name is required.
type DefaultToolRegistry ¶
type DefaultToolRegistry struct {
// contains filtered or unexported fields
}
DefaultToolRegistry stores local tools and MCP server tools.
func NewToolRegistry ¶
func NewToolRegistry() *DefaultToolRegistry
NewToolRegistry returns an empty tool registry.
func (*DefaultToolRegistry) Definitions ¶
func (r *DefaultToolRegistry) Definitions(ctx context.Context) ([]ToolDefinition, error)
func (*DefaultToolRegistry) Register ¶
func (r *DefaultToolRegistry) Register(t LocalTool) error
func (*DefaultToolRegistry) RegisterMCP ¶
func (r *DefaultToolRegistry) RegisterMCP(server MCPServer) error
type Document ¶
type Document struct {
ID string
Source string
Title string
Content string
MIMEType string
Meta map[string]string
}
Document is raw content to index for RAG retrieval.
type Embedder ¶
type Embedder interface {
Embed(ctx context.Context, texts []string) ([][]float32, error)
Dimensions() int
}
Embedder produces vector embeddings for text. Adapters target github.com/tmc/langchaingo/embeddings.Embedder.
type EndpointMount ¶
type EndpointMount struct {
// contains filtered or unexported fields
}
EndpointMount is the registration surface agents use to define rony services without holding a *rony.Server reference. The agent passes a mount during construction; implementations in std wire handlers through rony.Setup.
type Entry ¶
type Entry struct {
ID string
Kind Kind
Origin Origin
Name string
Content string
Source string // document URI, file path, collection name, etc.
Score float64
Meta map[string]string
}
Entry is a knowledge item from the static catalog or a RAG retrieval hit.
type GenerateOptions ¶
type GenerateOptions struct {
Model string
Temperature *float64
MaxTokens *int
StopWords []string
JSONMode bool
CandidateCount int
Streaming bool
ProviderSpecific any // opaque passthrough for adapter-specific options
}
GenerateOptions controls generation behavior. Adapters map these to langchaingo llms.CallOption values.
type Indexer ¶
type Indexer interface {
Index(ctx context.Context, docs []Document) error
DeleteSource(ctx context.Context, source string) error
}
Indexer ingests documents into a dynamic knowledge backend. Separated from Retriever so ingestion pipelines can run independently of queries.
type Knowledge ¶
type Knowledge interface {
StaticStore
Retriever
}
Knowledge combines the static catalog and dynamic RAG retrieval. Implementations may embed only one side; callers should handle unsupported operations from partial implementations as needed.
type LLM ¶
type LLM interface {
Model() Model
Generate(ctx context.Context, req Request) (Response, error)
Stream(ctx context.Context, req Request) (Stream, error)
}
LLM is a single language-model backend. Adapters wrap github.com/tmc/langchaingo/llms.Model.
func ByPriority ¶
ByPriority sorts models by descending priority.
func SelectEnforced ¶
SelectEnforced returns the model matching sel.ModelID.
func SelectFirst ¶
SelectFirst returns the first model in the pool.
func SelectPriority ¶
SelectPriority returns the model with the highest Priority value.
type LocalTool ¶
type LocalTool interface {
Definition() ToolDefinition
Execute(ctx context.Context, args json.RawMessage) (Message, error)
}
LocalTool is a local executable tool registered on the agent.
type LocalToolFunc ¶
type LocalToolFunc struct {
Def ToolDefinition
Fn func(ctx context.Context, args json.RawMessage) (Message, error)
}
LocalToolFunc adapts functions to LocalTool.
func (LocalToolFunc) Definition ¶
func (t LocalToolFunc) Definition() ToolDefinition
func (LocalToolFunc) Execute ¶
func (t LocalToolFunc) Execute(ctx context.Context, args json.RawMessage) (Message, error)
type MCPClientFactory ¶
type MCPClientFactory interface {
NewServer(ctx context.Context, cfg MCPServerConfig) (MCPServer, error)
}
MCPClientFactory creates MCP server connections from configuration. Implementations use github.com/modelcontextprotocol/go-sdk/mcp.Client.
type MCPContentBlock ¶
MCPContentBlock is an unstructured tool output. Adapters map from mcp.Content (TextContent, ImageContent, etc.).
type MCPPromptMessage ¶
MCPPromptMessage is one message returned by prompts/get.
type MCPPromptResult ¶
type MCPPromptResult struct {
Description string
Messages []MCPPromptMessage
}
MCPPromptResult is the resolved prompt from prompts/get.
type MCPPromptSummary ¶
MCPPromptSummary describes an MCP prompt listing entry.
type MCPRegistry ¶
type MCPRegistry interface {
List() []MCPServerConfig
Get(name string) (MCPServer, bool)
ConnectAll(ctx context.Context) error
CloseAll() error
}
MCPRegistry holds MCP servers available to an agent.
type MCPResourceContent ¶
MCPResourceContent is MCP resource payload.
type MCPResourceSummary ¶
type MCPResourceSummary struct {
URI string
Name string
Title string
Description string
MIMEType string
}
MCPResourceSummary describes an MCP resource listing entry.
type MCPServer ¶
type MCPServer interface {
Name() string
Connect(ctx context.Context) error
Close() error
ListTools(ctx context.Context) ([]MCPTool, error)
CallTool(ctx context.Context, name string, args json.RawMessage) (MCPToolResult, error)
ListResources(ctx context.Context) ([]MCPResourceSummary, error)
ReadResource(ctx context.Context, uri string) (MCPResourceContent, error)
ListPrompts(ctx context.Context) ([]MCPPromptSummary, error)
GetPrompt(ctx context.Context, name string, args map[string]string) (MCPPromptResult, error)
}
MCPServer is a connected MCP server an agent can call for tools and context. Adapters wrap mcp.ClientSession.
type MCPServerConfig ¶
type MCPServerConfig struct {
Name string
Transport MCPTransportKind
URL string // HTTP/SSE/streamable HTTP endpoint
Command []string // stdio: command and args
Meta map[string]string
}
MCPServerConfig describes how to connect to an external MCP server.
type MCPTool ¶
type MCPTool struct {
Name string
Title string
Description string
InputSchema json.RawMessage
OutputSchema json.RawMessage
}
MCPTool is a tool exposed by an MCP server. Adapters map from mcp.Tool.
type MCPToolResult ¶
type MCPToolResult struct {
Content []MCPContentBlock
StructuredContent json.RawMessage
IsError bool
}
MCPToolResult is the outcome of a tool invocation. Adapters map from mcp.CallToolResult.
type MCPTransportKind ¶
type MCPTransportKind string
MCPTransportKind selects how to connect to an MCP server. Adapters map to github.com/modelcontextprotocol/go-sdk/mcp transports.
const ( MCPTransportStreamableHTTP MCPTransportKind = "streamable-http" MCPTransportSSE MCPTransportKind = "sse" MCPTransportStdio MCPTransportKind = "stdio" )
type MapServiceRegistry ¶
type MapServiceRegistry struct {
// contains filtered or unexported fields
}
MapServiceRegistry is an in-memory service registry.
func NewMapServiceRegistry ¶
func NewMapServiceRegistry() *MapServiceRegistry
NewMapServiceRegistry returns an empty service registry.
func (*MapServiceRegistry) All ¶
func (r *MapServiceRegistry) All() []ServiceDescriptor
func (*MapServiceRegistry) Get ¶
func (r *MapServiceRegistry) Get(name string) (ServiceDescriptor, bool)
func (*MapServiceRegistry) Register ¶
func (r *MapServiceRegistry) Register(desc ServiceDescriptor) error
type Memory ¶
type Memory interface {
ForSession(sessionID string) SessionMemory
}
Memory provides session-scoped storage backends. Implementations may use in-memory storage, Postgres, embedded vector DBs (e.g. chromem-go), or external vector stores (e.g. Milvus).
type MemoryQuery ¶
MemoryQuery describes a memory lookup within a session.
type MemoryRecord ¶
type MemoryRecord struct {
ID string
Key string
Content []byte
Metadata map[string]string
Embedding []float32
CreatedAt time.Time
UpdatedAt time.Time
}
MemoryRecord is a stored memory item within a session.
type MemoryResult ¶
type MemoryResult struct {
Record MemoryRecord
Score float64
}
MemoryResult is a memory search hit.
type Message ¶
type Message struct {
Role Role `json:"role"`
Parts []Part `json:"parts,omitempty"`
// ToolCalls is set on assistant messages when the model requests tool.
ToolCalls []ToolCall `json:"toolCalls,omitempty"`
// ToolCallID and ToolName are set on tool-result messages.
ToolCallID string `json:"toolCallId,omitempty"`
ToolName string `json:"toolName,omitempty"`
}
Message is a chat turn. Multipart and tool-result messages are supported.
type Option ¶
type Option func(cfg *agentConfig)
Option configures an Agent.
func WithExecutor ¶
func WithExecutor(exec TaskExecutor) Option
func WithKnowledge ¶
func WithLLMPool ¶
func WithLogger ¶
func WithMCPServers ¶
func WithMCPServers(reg MCPRegistry) Option
func WithMaxToolIterations ¶
func WithMemory ¶
func WithRetriever ¶
func WithServer ¶
WithServer uses an existing rony.Server instead of creating one in New.
func WithServerOption ¶
func WithServerOption(opts ...rony.ServerOption) Option
WithServerOption forwards options to the underlying rony.Server. Ignored when WithServer supplies an existing server.
func WithService ¶
func WithService(desc ServiceDescriptor) Option
func WithServiceRegistry ¶
func WithServiceRegistry(reg ServiceRegistry) Option
func WithSessions ¶
func WithSessions(mgr *SessionManager) Option
func WithSkills ¶
func WithSkills(reg SkillRegistry) Option
func WithStaticKnowledge ¶
func WithStaticKnowledge(store StaticStore) Option
func WithTools ¶
func WithTools(reg ToolRegistry) Option
type Origin ¶
type Origin string
Origin distinguishes configured knowledge from RAG-retrieved knowledge.
type Part ¶
type Part struct {
Text string `json:"text,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
Binary []byte `json:"binary,omitempty"`
ToolCallID string `json:"toolCallId,omitempty"`
}
Part is one segment of a message. Text-only agents use TextPart. Adapters map richer SDK parts (e.g. langchaingo ContentPart) into this shape.
type Request ¶
type Request struct {
Messages []Message
Tools []ToolDefinition
Options GenerateOptions
}
Request is an LLM completion request.
type Response ¶
type Response struct {
Content string
ToolCalls []ToolCall
FinishReason string
ReasoningContent string
GenerationInfo map[string]any
Choices []Choice
}
Response is a non-streaming LLM completion result. When the backend returns multiple candidates, implementations should populate Choices; the first choice mirrors the top-level fields for convenience.
type RetrieveQuery ¶
RetrieveQuery describes a dynamic RAG lookup over indexed corpora.
type Retriever ¶
type Retriever interface {
Retrieve(ctx context.Context, q RetrieveQuery) ([]Entry, error)
}
Retriever performs dynamic knowledge lookup (RAG) at the request time. Implementations may use embedded vector DBs (e.g. chromem-go) or external stores (e.g. Milvus) over document corpora.
type Role ¶
type Role string
Role identifies who produced a message. Values align with github.com/tmc/langchaingo/llms.ChatMessageType.
type Selection ¶
Selection describes how to pick an LLM from a pool. ModelID is required when Strategy is StrategyEnforced.
type SelectorFunc ¶
SelectorFunc adapts a function to Selector.
type ServiceDescriptor ¶
type ServiceDescriptor struct {
Name string
Mount func(m EndpointMount) error
}
ServiceDescriptor binds a named rony service to the agent server.
type ServiceRegistry ¶
type ServiceRegistry interface {
Register(desc ServiceDescriptor) error
Get(name string) (ServiceDescriptor, bool)
All() []ServiceDescriptor
}
ServiceRegistry holds service descriptors registered on an agent.
type Session ¶
type Session struct {
ID string
Memory SessionMemory
Metadata map[string]string
Selection Selection
}
Session is one conversation or task run.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager creates and tracks agent sessions.
func NewSessionManager ¶
func NewSessionManager(mem Memory) *SessionManager
NewSessionManager returns a session manager backed by mem.
func (*SessionManager) Close ¶
func (m *SessionManager) Close(ctx context.Context, id string) error
Close removes a session from the active set and clears its memory.
func (*SessionManager) Create ¶
func (m *SessionManager) Create(_ context.Context, opts ...SessionOption) (*Session, error)
Create opens a new session.
type SessionMemory ¶
type SessionMemory interface {
SessionID() string
Save(ctx context.Context, rec MemoryRecord) error
Search(ctx context.Context, q MemoryQuery) ([]MemoryResult, error)
Delete(ctx context.Context, id string) error
Clear(ctx context.Context) error
}
SessionMemory stores and retrieves context for a single agent session. Conversation turns, tool results, and task notes for one session belong here.
type SessionOption ¶
type SessionOption func(*sessionCreateConfig)
SessionOption configures session creation.
func SessionWithID ¶
func SessionWithID(id string) SessionOption
SessionWithID sets an explicit session ID.
func SessionWithMetadata ¶
func SessionWithMetadata(metadata map[string]string) SessionOption
SessionWithMetadata attaches metadata to the session.
func SessionWithSelection ¶
func SessionWithSelection(sel Selection) SessionOption
SessionWithSelection sets the LLM selection strategy for the session.
type Skill ¶
type Skill struct {
Name string // unique key; the enum value the model selects
Description string // short summary; always advertised in the catalog
Instructions string // full body; injected only on activation
Tools []string // tool names unlocked while the skill is active
Triggers []string // keywords/phrases that suggest this skill (shown in catalog)
Examples []string // example user requests (shown in catalog)
Meta map[string]string // optional adapter metadata
}
Skill is a named capability the agent can activate on demand.
Only Name and Description are advertised to the model up front (progressive disclosure); Instructions and skill-scoped Tools enter the turn only after the model activates the skill via the ActivateSkillTool.
type SkillRegistry ¶
type SkillRegistry interface {
// List returns the advertisement cards for all available skills.
List(ctx context.Context) ([]SkillCard, error)
// Get returns the full skill, including Instructions and Tools.
Get(ctx context.Context, name string) (Skill, error)
}
SkillRegistry provides skill discovery (cheap cards) and activation (full body).
type StaticStore ¶
type StaticStore interface {
List(ctx context.Context, filter Filter) ([]Entry, error)
Get(ctx context.Context, id string) (Entry, error)
}
StaticStore holds configured prompts, skills, and facts. These entries are loaded at setup time and do not change during a session.
type Stream ¶
Stream delivers incremental LLM output. langchaingo adapters typically buffer WithStreamingFunc callbacks into Recv.
type TaskExecutor ¶
type TaskExecutor interface {
Start(ctx context.Context, name string, input any) (TaskHandle, error)
Get(ctx context.Context, id string) (TaskHandle, error)
Signal(ctx context.Context, id string, signal any) error
Cancel(ctx context.Context, id string) error
}
TaskExecutor runs task lifecycles. A flow-backed implementation will provide durable state transitions later.
type TaskHandle ¶
TaskHandle is a running or completed task instance.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
}
ToolCall is a model-initiated tool invocation. Adapters map to langchaingo llms.ToolCall.
type ToolDefinition ¶
ToolDefinition describes a tool the model may call. Parameters hold JSON Schema (object). Adapters map to langchaingo FunctionDefinition.
type ToolExecutor ¶
type ToolExecutor interface {
Definitions(ctx context.Context) ([]ToolDefinition, error)
Execute(ctx context.Context, call ToolCall) (Message, error)
}
ToolExecutor resolves and runs tool calls.
type ToolRegistry ¶
type ToolRegistry interface {
ToolExecutor
Register(t LocalTool) error
RegisterMCP(server MCPServer) error
}
ToolRegistry holds local and MCP-backed tools.
type TurnResult ¶
TurnResult is the outcome of a completed turn.