agents

package
v1.6.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	RecordOff      = "off"
	RecordMetadata = "metadata"
	RecordFull     = "full"
)

Recording levels of the journal.

Server is the name of the built-in MCP server; allowed_mcp ["agents"] makes a key that may only talk to agents.

Variables

View Source
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 Tools

func Tools() []*mcp.Tool

Tools are the tools of the agents server, named without the server prefix.

func ValidRecording

func ValidRecording(v string) bool

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.

func (*Guard) Check

func (gd *Guard) Check(ctx context.Context, text string) (string, string, error)

Check returns the text to deliver and, when a person should see it first, why; an error refuses the message.

type Journal

type Journal interface {
	Record(ctx context.Context, ev Event) error
}

Journal keeps conversation events for audit and for exporters.

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

func NewRedisJournal(rdb redis.Cmdable, key string, maxLen int64, maxEventBytes int) *RedisJournal

func (*RedisJournal) Record

func (j *RedisJournal) Record(ctx context.Context, ev Event) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds the policy; guard and journal may be nil.

func New

func New(store Store, cfg Config, guard *Guard, journal Journal) *Service

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

func (s *Service) Me(ctx context.Context, id *apikeys.Identity) (*proxydb.Agent, error)

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.

func (*Service) Sweep

func (s *Service) Sweep(ctx context.Context, every time.Duration)

Sweep deletes tasks unchanged for longer than the retention, every interval, until ctx ends. No retention keeps them forever.

func (*Service) Tools

func (s *Service) Tools() []*mcp.Tool

Tools are the service's tools, for the MCP gateway.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL