Documentation
¶
Overview ¶
Package evolve connects Cortex to altk-evolve, a service that learns guidelines from agent trajectories (https://github.com/AgentToolkit/altk-evolve), using only the tools a stock `evolve-mcp --transport sse` server exposes.
The plugin does two things, both optional:
- Inject. On a session's first main-agent inference request it asks evolve (get_guidelines_with_attribution) for the guidelines relevant to the session's task in the serve namespace, caches them per session, and appends them to the system instructions of every main-agent request in that session as a delimited <evolve-guidelines> block. The block is byte-stable across turns so prompt caching keeps working.
- Learn. It records each completed main-agent turn as OpenAI chat messages and, when the session has been idle for idle_after_seconds, sends the new turns to evolve (process_trajectory) as one identified batch. Evolve generates guidelines from them into the learn namespace.
By default the two namespaces are a review gate. Session content includes tool output the agent read, so a guideline distilled from it can carry text an attacker wrote. Learned guidelines therefore land in learn_namespace, which is not injected from; a person copies the ones worth keeping into serve_namespace. Setting the two to the same namespace skips the review: whatever evolve learns is served to the next session.
Every failure fails open. Evolve unreachable, slow, or returning nonsense means the request goes upstream untouched; the guidelines are an improvement, never a dependency.
Index ¶
- Variables
- type Batch
- type Evolve
- type Guideline
- type Plugin
- func (p *Plugin) Capabilities() pipeline.PluginCapabilities
- func (p *Plugin) ConfigSchema() []pipeline.FieldSchema
- func (p *Plugin) Configure(raw json.RawMessage) error
- func (p *Plugin) Init(context.Context) error
- func (p *Plugin) Metrics() []pipeline.Metric
- func (p *Plugin) Name() string
- func (p *Plugin) OnFinish(_ context.Context, pctx *pipeline.Context)
- func (p *Plugin) OnRequest(ctx context.Context, pctx *pipeline.Context) (action pipeline.Action)
- func (p *Plugin) OnResponse(context.Context, *pipeline.Context) pipeline.Action
- func (p *Plugin) RawConfig() json.RawMessage
- func (p *Plugin) Shutdown(ctx context.Context) error
- type Trajectory
Constants ¶
This section is empty.
Variables ¶
ErrUnavailable wraps every failure to get an answer from evolve: transport errors, timeouts, tool errors and undecodable results. The plugin fails open on all of them.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
Source string `json:"source"`
ConversationID string `json:"conversation_id"`
BatchID string `json:"batch_id"`
Scope string `json:"scope,omitempty"`
}
Batch is evolve's idempotency key for one bounded contribution to a conversation: re-sending the same batch is skipped by evolve.
type Evolve ¶
type Evolve interface {
// Guidelines returns the guidelines relevant to a task from a namespace.
Guidelines(ctx context.Context, namespace, task, sessionID string) ([]Guideline, error)
// Learn sends a trajectory batch to evolve, which generates guidelines from
// it into namespace.
Learn(ctx context.Context, namespace string, t Trajectory) error
}
Evolve is the plugin's view of an altk-evolve service. The concrete implementation (mcpEvolve) calls the stock evolve MCP server's tools; tests inject a fake.
type Guideline ¶
type Guideline struct {
ID string
Content string
Revision *int
// Source is the trajectory the guideline was learned from (its source task
// id), or several, comma-separated, for a guideline consolidated from more
// than one.
Source string
}
Guideline is one served guideline plus the provenance agentop shows for it.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is the evolve plugin.
func (*Plugin) Capabilities ¶
func (p *Plugin) Capabilities() pipeline.PluginCapabilities
func (*Plugin) ConfigSchema ¶
func (p *Plugin) ConfigSchema() []pipeline.FieldSchema
ConfigSchema implements pipeline.SchemaProvider.
func (*Plugin) OnFinish ¶
OnFinish records the completed turn for learning. It runs after the response is on the wire, and only appends to the session's recorder.
func (*Plugin) OnResponse ¶
func (*Plugin) RawConfig ¶
func (p *Plugin) RawConfig() json.RawMessage
RawConfig implements pipeline.RawConfigProvider.
type Trajectory ¶
type Trajectory struct {
Messages []map[string]any `json:"messages"`
ContextMessages []map[string]any `json:"context_messages,omitempty"`
Batch *Batch `json:"batch,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Model string `json:"model,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Trajectory is evolve's processing input (altk_evolve.processing.Trajectory).