agentcredential

package
v0.0.54 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 8 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 agentcredential holds the identity broker credentials of registered agents, in memory only, for the server, which registers a session's main agent at run entry and each helper agent when it is created, and the MCP broker, which presents them on gateway calls. A credential is never persisted and never given to the engine or the model. It also holds the run each helper acts in, delegated to it, and carries the main agent's run on the context, so a gateway call names its run.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCredential is a lookup's error when nothing is held for the key; a
	// lookup never registers.
	ErrNoCredential = errors.New("agentcredential: no credential held")
	// ErrDropped refuses to store a registration whose root was dropped, or
	// the holder closed, while it was in flight.
	ErrDropped = errors.New("agentcredential: entry dropped during registration")
	// ErrOtherAgent refuses a registration that returned an agent other than
	// the one registered.
	ErrOtherAgent = errors.New("agentcredential: broker returned another agent")
	// ErrExpired refuses a registration that returned an expired credential.
	ErrExpired = errors.New("agentcredential: broker returned an expired credential")
)

Functions

func WithRun added in v0.0.53

func WithRun(ctx context.Context, run Run) context.Context

WithRun returns ctx carrying run as the main agent's run.

Types

type Credential

type Credential struct {
	// BrokerSessionID is the broker session the agent was registered to; the
	// credential verifies only there.
	BrokerSessionID string
	Agent           identitybroker.AgentRef
	// Owner is the owner the agent was registered with.
	Owner identitybroker.Owner
	// Incarnation is the incarnation the agent was registered with: for a
	// root's main agent, the root session's.
	Incarnation string
	Token       identitybroker.Token
	ExpiresAt   time.Time
}

Credential is a held agent credential and what it was registered with.

type Delegation added in v0.0.53

type Delegation struct {
	// ID is the delegation ID the helper's calls name.
	ID string
	// Run is the helper's own run, and its owner.
	Run Run
	// DelegatingRun is the run that delegated, and DelegatingAgentSession the
	// session of the agent that run is bound to: the root session for the
	// main agent, or a helper's own session.
	DelegatingRun          string
	DelegatingAgentSession string
	// StandInDelegatingRun marks DelegatingRun as standing in for the API
	// request that started the work: the run of the root's main agent mecak8s
	// starts for a RunTeam call, which did not itself delegate to the helper.
	StandInDelegatingRun bool
}

Delegation is a helper agent's delegation as reported to the identity broker: the helper's run, delegated to it by a run of its parent agent.

type HelperDelegation added in v0.0.53

type HelperDelegation struct {
	AgentSessionID string
	Delegation
}

HelperDelegation is a delegation and the helper session it delegates to.

type Holder

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

Holder holds agent credentials. Callers that take their own lock around Drop take it before the holder's; the holder never calls out while holding its own lock.

func New

func New(broker identitybroker.Service, now func() time.Time) *Holder

New returns a Holder registering through broker, with now as its clock.

func (*Holder) ClearDelegation added in v0.0.53

func (h *Holder) ClearDelegation(key Key)

ClearDelegation forgets the current delegation of key's helper, so its gateway calls name no run until it is delegated again. Delegations already recorded are kept for the chains of later ones.

func (*Holder) Close

func (h *Holder) Close()

Close drops every credential; later and in-flight stores are refused with ErrDropped, and lookups return ErrNoCredential. A nil Holder holds nothing.

func (*Holder) Credential

func (h *Holder) Credential(ctx context.Context, key Key, renew bool) (Credential, error)

Credential is the MCP broker's lookup. With no entry for key it returns ErrNoCredential: it never opens, reopens, or registers. Past renewAt, or with renew set (after svid_expired), it renews the credential. A helper agent's credential is also registered again when its root's main agent has moved to another broker session since: the helper moves there too, after its parent, keeping its identity. Renewal is single-flight per key: every lookup, the first included, waits for the one in flight or for its own context, and one lookup's cancellation does not end the renewal. A renewal is stored only if key's root was not dropped and the holder not closed since it started (ErrDropped otherwise). If it fails otherwise, a lookup past half-life gets the held credential while it has not expired; a lookup with renew, made after the broker refused the held credential, or for a helper that could not move, gets the renewal's error.

func (*Holder) Delegation added in v0.0.53

func (h *Holder) Delegation(key Key) (Delegation, bool)

Delegation returns the current delegation of key's helper, and whether one is held.

func (*Holder) Delegations added in v0.0.53

func (h *Holder) Delegations(root string) []HelperDelegation

Delegations returns every delegation recorded for root's session tree in the order they were recorded, so each delegating run comes before the runs it delegated to: the order a reopened broker session needs them reported again in.

func (*Holder) Drop

func (h *Holder) Drop(root string)

Drop drops every credential held for root's session tree, and refuses to store any registration or renewal for it already in flight. Callers that guard their own state with a lock call it holding that lock. A nil Holder holds nothing.

func (*Holder) Ensure

func (h *Holder) Ensure(ctx context.Context, key Key, req identitybroker.RegisterAgentRequest, admit func() error) error

Ensure is the run-entry path. It registers the agent with req unless the held entry has the same incarnation and broker session and is before renewAt. A registration must return an unexpired credential that identitybroker.CheckRegistration accepts, for an agent that, with a credential held for the same incarnation, is the held agent; otherwise Ensure returns ErrExpired or ErrOtherAgent and keeps what it held. admit is called, without the holder's lock, only once such a registration succeeded, and its error is returned unchanged; the registration is then stored only if key's root was not dropped since Ensure started and the holder is not closed (ErrDropped). A broker error is returned unchanged.

func (*Holder) Held

func (h *Holder) Held(key Key) (Credential, bool)

Held returns the credential held for key without renewing it, and whether one is held.

func (*Holder) MoveHelpers added in v0.0.53

func (h *Holder) MoveHelpers(ctx context.Context, root string) error

MoveHelpers registers every helper agent held for root's session tree into the broker session root's main agent is registered to now, if it is not there already, parents first, keeping each helper's identity: what a reopened broker session needs once its main agent registered again. It returns the moves that failed, joined; a helper that failed to move gets no credential until a later lookup moves it.

func (*Holder) ReportDelegationAgain added in v0.0.53

func (h *Holder) ReportDelegationAgain(ctx context.Context, key Key) error

ReportDelegationAgain reports key's helper's current delegation, and the delegations its delegating run descends from, into the broker session its credential is held in now. A caller that set the delegation after reporting it to a broker session the helper has since left calls it, so the session the helper moved to sees the delegation its calls name. It returns ErrNoCredential when nothing is held for key.

func (*Holder) SetDelegation added in v0.0.53

func (h *Holder) SetDelegation(key Key, d Delegation) error

SetDelegation records d as the current delegation of key's helper, once the broker accepted it. It returns ErrNoCredential, recording nothing, when no credential is held for key. When the helper moves to another broker session, its current delegation is reported there again, after the delegations its delegating run descends from; the design gives a delegation no end, so each is kept, to find those, until its root is dropped.

type Key

type Key struct{ RootSessionID, AgentSessionID string }

Key names a held credential. For a session's main agent both IDs are the root host session; for a helper agent, AgentSessionID is its own session.

type Run added in v0.0.53

type Run struct {
	ID    string
	Owner identitybroker.Owner
}

Run is the run a root session's main agent is in: the server's run ID and the run's owner, the user who started it. The server puts it on the context of every run it hands the engine; the engine passes context values to tool calls and to the runs of helpers it starts, background ones included.

func RunFromContext added in v0.0.53

func RunFromContext(ctx context.Context) (Run, bool)

RunFromContext returns the main agent's run ctx carries, and whether it carries one.

func (Run) IsZero added in v0.0.53

func (r Run) IsZero() bool

IsZero reports whether r names no run.

Jump to

Keyboard shortcuts

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