Documentation
¶
Overview ¶
Package agentframework connects the Microsoft Agent Framework for Go to a Taisce deployment, on four of the framework's own seams: a context provider that recalls before a run and observes after it, a second that replaces a long history with the deployment's context, a store that keeps the framework's session where the memory formed from it already lives, and a binding of the deployment's passage search to the framework's text-search seam.
It decides what the model is handed from memory and what of a run is stored. It must not decide what memory holds, rank what a recall returns, or summarise anything itself: an adapter that decides things locally is how behaviour forks per language. The conformance suite holds it to the same rules as every other adapter.
The session store is the one seam an application drives rather than the framework: when a session is worth persisting is the application's decision, and a provider that wrote on every run would make it invisibly, at the cost of a request per turn.
Nothing here offers erasure or export to a model. Those are the application's, through the client, with a key the agent process does not hold.
Index ¶
- Constants
- func MapPassages(results taisce.PassageResults, sayWhenApproximate bool) []textsearch.Result
- func NewTextSearch(config TextSearchConfig) (func(context.Context, string) ([]textsearch.Result, error), error)
- func NewTextSearchProvider(config TextSearchConfig, options textsearch.Config) (*textsearch.Provider, error)
- type Compaction
- type CompactionConfig
- type Config
- type ContextProvider
- type LoadedSession
- type SavedSession
- type SessionStore
- func (s *SessionStore) Delete(ctx context.Context, sessionID, dataSubjectID, expectedVersion string) error
- func (s *SessionStore) Load(ctx context.Context, sessionID, dataSubjectID string) (LoadedSession, bool, error)
- func (s *SessionStore) Save(ctx context.Context, session *agent.Session, ...) (SavedSession, error)
- type TextSearchConfig
Constants ¶
const DefaultSessionKind = "state"
DefaultSessionKind is the object kind sessions are stored under. The deployment treats it as an opaque label and lists by it, which is what lets an operator see sessions apart from other stored objects.
const SourceID = "taisce"
SourceID stamps the messages this package adds, so a filter can tell them from what a person said.
const UntrustedProperty = "taisce.untrusted"
UntrustedProperty marks the memory message in its AdditionalProperties. A model sees the text and not the property; the property is for the application and for any middleware that routes untrusted input differently.
Variables ¶
This section is empty.
Functions ¶
func MapPassages ¶
func MapPassages(results taisce.PassageResults, sayWhenApproximate bool) []textsearch.Result
MapPassages turns what the deployment returned into what the framework consumes.
Exported and separate from the call so it can be held to its rules without a deployment: a mapping tested through an HTTP stub is a test of the stub.
func NewTextSearch ¶
func NewTextSearch(config TextSearchConfig) (func(context.Context, string) ([]textsearch.Result, error), error)
NewTextSearch returns the search function the framework's provider calls.
Returned as a function rather than wrapped in a type, because that is the shape the framework's seam takes: a caller who wants the framework's own provider options, its on-demand tool mode or its recent-message memory passes this to textsearch.NewContextProvider and configures the rest there. NewTextSearchProvider below is that call with this package's defaults.
func NewTextSearchProvider ¶
func NewTextSearchProvider(config TextSearchConfig, options textsearch.Config) (*textsearch.Provider, error)
NewTextSearchProvider builds the framework's text-search provider over one deployment.
Every result reaches the model under the same untrusted prefix the context provider uses: a passage is something somebody said, so it is data and never an instruction, on this seam as on every other. A caller's own ContextFormatter is wrapped rather than replaced — their formatting survives and the mark comes first regardless, because a formatter that could drop it would make the mark a convention.
Types ¶
type Compaction ¶
type Compaction struct {
// contains filtered or unexported fields
}
Compaction replaces a long loaded history with the deployment's context before the model runs.
Replacement, never a summary: the history a history provider loaded is swapped for one untrusted user message carrying the deployment's segments and verbatim turns unchanged. The deployment already holds every turn, and a summary written here would be a second, unprovable account of them. A context that cannot be fetched leaves the history as it was, so the model reads more rather than less and the run goes on.
func NewCompaction ¶
func NewCompaction(config CompactionConfig) (*Compaction, error)
NewCompaction builds the provider.
func (*Compaction) Invoked ¶
func (c *Compaction) Invoked(context.Context, agent.InvokedContext) error
Invoked does nothing: what a run said is stored by the ContextProvider.
type CompactionConfig ¶
type CompactionConfig struct {
// Client reaches the deployment. Required.
Client *taisce.Client
// DataSubjectID is whose history the context is. Required: a context is one person's history.
DataSubjectID string
// AfterMessages is the loaded history length, system messages aside, above which the history is
// replaced. Required and positive.
AfterMessages int
// MaxCharacters bounds the context; zero is the deployment's default.
MaxCharacters int
// OnError hears a context that could not be fetched, with stage "context". It is survived.
OnError func(stage string, err error)
}
CompactionConfig configures a Compaction provider.
type Config ¶
type Config struct {
// Client reaches the deployment. Required.
Client *taisce.Client
// DataSubjectID is the person this agent's memory is about. Empty recalls and stores without one.
DataSubjectID string
// RunID is part of every turn's key: the same turn in another run is another memory.
RunID string
// MaxCharacters bounds what a recall returns; zero is the deployment's default.
MaxCharacters int
// SourceRoles narrows a recall to facts said by these roles; empty is the deployment's default.
SourceRoles []string
// OnError hears every failure: "recall", which is survived, and "observe", which is also returned
// to the run. It is how an operator finds out about a recall the agent went on without.
OnError func(stage string, err error)
}
Config configures a ContextProvider.
type ContextProvider ¶
type ContextProvider struct {
// contains filtered or unexported fields
}
ContextProvider recalls before a run and observes after it.
func NewContextProvider ¶
func NewContextProvider(config Config) (*ContextProvider, error)
NewContextProvider builds the provider. It refuses a configuration with no client.
func (*ContextProvider) Invoked ¶
func (p *ContextProvider) Invoked(ctx context.Context, invoked agent.InvokedContext) error
Invoked stores the turn after a run that succeeded: the person's messages from this run's input and the assistant's final words. Nothing else becomes memory by default — not history a history provider loaded, which was stored when it happened; not a message a provider or the framework added; not a tool call or a tool's answer. A failed run stores nothing, because a failed turn is not a memory. A store that fails is reported and returned, and the framework hands it to the application: a lost turn is invisible until somebody asks what the system holds about them.
func (*ContextProvider) Invoking ¶
func (p *ContextProvider) Invoking(ctx context.Context, invoking agent.InvokingContext) ([]*message.Message, []agent.Option, error)
Invoking recalls for the person's latest message and, when memory holds something, adds exactly one user message carrying it, marked untrusted. Never a system message: recalled text was written by whoever the agent talked to, and a system message is the highest trust a model gives. A recall that fails is reported and survived: the agent runs without memory rather than not at all.
type LoadedSession ¶
LoadedSession is a session read back, with the version it was read at.
type SavedSession ¶
SavedSession is what a save returned: the version the next save should expect to replace.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore keeps an agent session where the memory it belongs to already lives.
Why this is not a convenience ¶
The framework marshals a session and hands it back; it ships no durable store, so every application invents one. Inventing it in the application's own database is the expensive mistake, and the reason is governance rather than tidiness: a session and the memory formed from it are erased by the same request from the same person. Split across two systems, a deletion has two places to sweep, one of which can produce a counted residual and one of which cannot, and the honest answer to "is it gone" becomes "it is gone from the part we can measure".
So a session is an opaque object under the person it belongs to. The deployment never reads it, expires it with that person's retention, and removes it with that person's erasure, on the same receipt as the facts formed from their conversations.
Whose session it is, is checked by the deployment ¶
One credential opens a project and a project holds every end user's objects, so an application serving many people could hand one person's session to another; nothing in the application is a boundary against that, only care. Every call here names the subject, and the deployment answers another person's session exactly as one that does not exist.
Concurrency is the caller's to declare ¶
A save carries the version it expects to replace and the deployment refuses a stale one, so two turns of the same session cannot silently lose one of their writes. Passing no version is not last-write-wins: the deployment replays an identical save and refuses a changed one, so a second writer who did not read first is told rather than obeyed. Naming the version you expect to replace is still what to do.
What this does not do ¶
It does not run inside the framework's history seam. An application decides when a session is worth persisting — which is usually after a run, and sometimes not at all — and a provider that wrote on every run would make that decision for it, invisibly, at the cost of a request per turn.
func NewSessionStore ¶
func NewSessionStore(client *taisce.Client, kind string) (*SessionStore, error)
NewSessionStore builds a store over one deployment. An empty kind takes DefaultSessionKind.
func (*SessionStore) Delete ¶
func (s *SessionStore) Delete(ctx context.Context, sessionID, dataSubjectID, expectedVersion string) error
Delete removes a person's session. A session that is not there is already removed.
func (*SessionStore) Load ¶
func (s *SessionStore) Load(ctx context.Context, sessionID, dataSubjectID string) (LoadedSession, bool, error)
Load reads a person's session back. found is false when that person has no session by that id.
Not an error, because "this person has not been here before" is the ordinary first turn of every conversation and not something anybody should have to catch. A session belonging to somebody else is also not found, which is the check that makes one person's state unreachable to another.
func (*SessionStore) Save ¶
func (s *SessionStore) Save(ctx context.Context, session *agent.Session, sessionID, dataSubjectID, expectedVersion string) (SavedSession, error)
Save marshals a session and stores it under the person it belongs to.
expectedVersion is the version this save expects to replace; empty on the first save of a session.
type TextSearchConfig ¶
type TextSearchConfig struct {
// Client reaches the deployment. Required.
Client *taisce.Client
// Limit is how many passages to return; zero is the deployment's default, and the deployment
// bounds it regardless.
Limit int
// DataSubjectID narrows the search to one person's words, or empty for the project's. A passage
// is somebody's words, so a search narrowed to one person must not quote anybody else.
DataSubjectID string
// SourceRole is whose messages to search; empty is the deployment's default, the person's own.
SourceRole string
// SayWhenApproximate adds a line saying the index behind the answer is still building. On by
// default, because the alternative is a model answering confidently from a partial set.
SayWhenApproximate *bool
// OnError hears a search that failed, with stage "passages". The framework survives a failed
// search by leaving the input unchanged, so without this nothing would say it happened.
OnError func(stage string, err error)
}
TextSearchConfig is what a search asks the deployment for.