Documentation
¶
Overview ¶
Package native is the in-process backend: an agentturn.Agent driven directly, with the session.Recorder that writes its store, which is followed on the same store value. It is the reference the other backends follow.
Control is the agent's. Live is the agent's Subscribe, narrowed by client.FromEvent, with the questions Backend.Ask puts to the user. Record is the store's Follow, which wakes on each append with no polling.
Index ¶
- type Backend
- func (b *Backend) Agent() *agentturn.Agent
- func (b *Backend) Ask(ctx context.Context, q client.Question) (client.Reply, error)
- func (b *Backend) Control() client.Control
- func (b *Backend) Live(ctx context.Context) iter.Seq2[client.LiveEvent, error]
- func (b *Backend) Record() client.Record
- func (b *Backend) SessionID() string
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend drives one agent and follows the session its recorder writes.
func New ¶
New returns the backend for agent, whose events rec records. The caller attaches rec to agent, with rec.Attach, before the first run: the recorder has to be subscribed ahead of this backend, so that an event's entry is in the store before the client sees the event. The recorder's store must be able to follow: every store of agentsession is.
New hands agent the inputs the session owes (session.Recorder.Requeue): those queued on a resumed session, or on a fork's base, that no run took before the process that accepted them ended. They are part of the history, listed as queued (view.Model.Queued), and the next run takes them, after its prompt, as it would have in the process that accepted them. Call New before the agent's first run, or the run's end closes them and they are dropped.
func (*Backend) Agent ¶
Agent returns the agent, for what the contract does not carry yet: the configuration and the transcript.
func (*Backend) Ask ¶
Ask puts q to the user and waits for the reply: the hook a host gives the code that asks while a call runs, a sub-agent's policy or a tool's elicitor. Every Backend.Live subscriber, and one that subscribes while q waits, gets a client.QuestionAsked; client.Control.Reply answers it. When ctx ends first, an abort of the run, the question is closed unanswered and Ask returns ctx's error. q.ID is set by Ask.
func (*Backend) Control ¶
Control implements client.Backend.
func (*Backend) Live ¶
Live subscribes to the agent when it is called, not when the result is first ranged over, so a client that calls it and then starts a run misses nothing. The subscription ends when ctx is done. Events queue without bound until the client takes them: the agent's delivery is a barrier, and a slow client must not stall the run or the recorder.
type Option ¶
type Option func(*Backend)
Option configures New.
func WithHeadMove ¶
func WithHeadMove(before func(context.Context) error, after func(context.Context, *agentsession.Session) error) Option
WithHeadMove sets two hooks around a client.Control.ContinueFrom. before runs before anything moves, while the recorder still writes the branch being left; after runs once the recorder, the agent and the pending calls are on the new branch, with the session as it stands there, and again, with the session back on the old branch, when the move fails and is undone. A host whose state follows the path (skill grants) ends it in before and rebuilds it from the path in after. An error from before refuses the move; an error from after fails it, or, in the undo, is joined to the move's error.
func WithRelease ¶
func WithRelease(fn func(ctx context.Context, end *agentturn.RunEnd, answers []agentturn.Answer) ([]agentturn.Answer, error)) Option
WithRelease sets what Answer does with the answers it was given before it resumes the run: fn gets the RunEnd the last run left pending calls with (nil when the pending calls were restored from a record, so no run of this process produced them) and returns the answers to resume with. agentpolicy's Engine.Release is the use: it answers the calls it only held, and fails when one is left unanswered.
func WithRunContext ¶
WithRunContext decorates the context of every run the backend starts (Prompt, Answer) and of the head move, after the backend put its own on it. fn is called under the backend's lock, so it must not call back into Control (Prompt, Answer, ContinueFrom), which would deadlock. It is how a host puts what its hooks read on the context: a recorder, a session ID, a grant scope.