Documentation
¶
Overview ¶
Package agents lets the agents of different people talk through Keystone: an agent is a client key with a card, and a task is one request from one agent to another, delivered to the recipient's inbox (MCP server "agents"). The model follows A2A: tasks, context ids, messages and statuses.
Index ¶
- Constants
- Variables
- func Tools() []*mcp.Tool
- func ValidRecording(v string) bool
- type Card
- type Config
- type Event
- type Guard
- type Journal
- type RedisJournal
- type Service
- func (s *Service) Call(ctx context.Context, id *apikeys.Identity, tool string, args json.RawMessage) (*mcp.CallToolResult, error)
- func (s *Service) Get(ctx context.Context, id *apikeys.Identity, taskID string) (*proxydb.AgentTask, error)
- func (s *Service) Inbox(ctx context.Context, id *apikeys.Identity, all bool, limit int) ([]*proxydb.AgentTask, error)
- func (s *Service) List(ctx context.Context, id *apikeys.Identity) (me *proxydb.Agent, out []*proxydb.Agent, err error)
- func (s *Service) Me(ctx context.Context, id *apikeys.Identity) (*proxydb.Agent, error)
- func (s *Service) Outbox(ctx context.Context, id *apikeys.Identity, limit int) ([]*proxydb.AgentTask, error)
- func (s *Service) Register(ctx context.Context, id *apikeys.Identity, c Card) (*proxydb.Agent, error)
- func (s *Service) Reply(ctx context.Context, id *apikeys.Identity, taskID, text, status string) (*proxydb.AgentTask, error)
- func (s *Service) Send(ctx context.Context, id *apikeys.Identity, to, text, contextID string) (*proxydb.AgentTask, error)
- func (s *Service) Sweep(ctx context.Context, every time.Duration)
- func (s *Service) Tools() []*mcp.Tool
- type Store
Constants ¶
const ( RecordOff = "off" RecordMetadata = "metadata" RecordFull = "full" )
Recording levels of the journal.
const Server = registry.ReservedMCPServer
Server is the name of the built-in MCP server; allowed_mcp ["agents"] makes a key that may only talk to agents.
Variables ¶
var ( // ErrInvalid is a request the caller can fix; its text says how. ErrInvalid = errors.New("invalid") // ErrDenied is a request the policy refuses. ErrDenied = errors.New("permission_denied") )
Functions ¶
func ValidRecording ¶
ValidRecording reports whether v is a recording level; "" keeps the default.
Types ¶
type Card ¶
type Card struct {
Description string `json:"description,omitempty"`
Skills []string `json:"skills,omitempty"`
Repos []string `json:"repos,omitempty"`
AcceptFrom []string `json:"accept_from,omitempty"`
}
Card is what an agent says about itself.
type Config ¶
type Config struct {
MaxDepth int32 // tasks one task may cause in a chain
MaxMessages int64 // messages in one conversation (context id)
MaxMessageBytes int // one message
Recording string
Retention time.Duration
}
Config bounds conversations; zero values take the defaults.
type Event ¶
type Event struct {
Type string `json:"type"` // task.created, task.<status>
At time.Time `json:"at"`
TaskID string `json:"task_id"`
ContextID string `json:"context_id"`
From string `json:"from"`
FromOwner string `json:"from_owner,omitempty"`
To string `json:"to"`
ToOwner string `json:"to_owner,omitempty"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
Depth int32 `json:"depth"`
Bytes int `json:"bytes"`
// Only at recording level full; cut to the event limit, with the hash of the whole.
Text string `json:"text,omitempty"`
Truncated bool `json:"truncated,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
Event is one journal entry of a conversation.
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard runs the model guardrails on messages between agents. PII is blocked or masked as GUARDRAILS_PII_ACTION says; a suspected injection is held for a person (input-required) instead of blocked, unless its action is log.
func NewGuard ¶
func NewGuard(g *guardrails.Guardrails) *Guard
NewGuard is nil when guardrails are off, so messages pass unchecked.
type RedisJournal ¶
type RedisJournal struct {
// contains filtered or unexported fields
}
RedisJournal is the best-effort journal: a capped Redis stream. The oldest events go first when it is full, and the write never blocks a conversation for longer than the client's timeout.
func NewRedisJournal ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds the policy; guard and journal may be nil.
func (*Service) Call ¶
func (s *Service) Call(ctx context.Context, id *apikeys.Identity, tool string, args json.RawMessage) (*mcp.CallToolResult, error)
Call runs one tool for the caller. Policy refusals and mistakes come back as tool errors the model can act on, as MCP wants.
func (*Service) Get ¶
func (s *Service) Get(ctx context.Context, id *apikeys.Identity, taskID string) (*proxydb.AgentTask, error)
Get is a task the caller sent or received.
func (*Service) Inbox ¶
func (s *Service) Inbox(ctx context.Context, id *apikeys.Identity, all bool, limit int) ([]*proxydb.AgentTask, error)
Inbox is the open tasks sent to the caller, with their messages.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, id *apikeys.Identity) (me *proxydb.Agent, out []*proxydb.Agent, err error)
List is the agents the caller can see, itself included.
func (*Service) Me ¶
Me is the caller's agent, registered on first use. Its name is the key's and cannot change: whoever mints keys names agents, so no agent can take another's name to pass an accept_from list.
func (*Service) Outbox ¶
func (s *Service) Outbox(ctx context.Context, id *apikeys.Identity, limit int) ([]*proxydb.AgentTask, error)
Outbox is the tasks the caller sent, without their messages.
func (*Service) Register ¶
func (s *Service) Register(ctx context.Context, id *apikeys.Identity, c Card) (*proxydb.Agent, error)
Register writes the caller's card. Its name and recording level are not the agent's to choose.
func (*Service) Reply ¶
func (s *Service) Reply(ctx context.Context, id *apikeys.Identity, taskID, text, status string) (*proxydb.AgentTask, error)
Reply answers a task. Its recipient moves it to working, input-required, completed or failed; its sender answers a question (back to working) or cancels it.
func (*Service) Send ¶
func (s *Service) Send(ctx context.Context, id *apikeys.Identity, to, text, contextID string) (*proxydb.AgentTask, error)
Send opens a task for agent to. With contextID it continues a conversation the caller takes part in, one level deeper.
type Store ¶
type Store interface {
UpsertAgent(ctx context.Context, a *proxydb.Agent) error
GetAgentByKey(ctx context.Context, keyID string) (*proxydb.Agent, error)
GetAgentByName(ctx context.Context, name string) (*proxydb.Agent, error)
GetAPIKeyByLowerName(ctx context.Context, name string) (*proxydb.APIKey, error)
ListAgents(ctx context.Context, f proxydb.AgentFilter) ([]*proxydb.Agent, error)
ContextDepth(ctx context.Context, contextID, toAgent string) (int32, error)
WithAgentMessages(ctx context.Context, tasks []*proxydb.AgentTask) error
AgentInContext(ctx context.Context, keyID, contextID string) (bool, error)
CreateAgentTask(ctx context.Context, t *proxydb.AgentTask, text string, maxMessages int64) error
AddAgentMessage(ctx context.Context, taskID, fromAgent, role, text, status, reason string, maxMessages int64) (*proxydb.AgentTask, error)
GetAgentTask(ctx context.Context, id string) (*proxydb.AgentTask, error)
ListAgentTasks(ctx context.Context, f proxydb.TaskFilter) ([]*proxydb.AgentTask, error)
DeleteAgentTasksBefore(ctx context.Context, cutoff time.Time) (int64, error)
}
Store is the slice of proxydb the service needs.