Documentation
¶
Overview ¶
Package basetools is the set of tools every project's Patch has, whoever the providers are.
A provider publishes what only it knows: what its resources mean, how to build one, what to check when one is unwell. Everything underneath that — list what is there, read one, describe a kind's fields, find out where a service is offered, find out how much of the quota is left — is the same work for every service on the platform, and a platform that makes each provider build it again gets a different answer from each of them.
Two properties hold for every tool here:
- It runs as the person who asked. The tools are handed a projectapi.Project already bound to the caller's own credential; there is no credential of the service's own anywhere on this path, so a tool call can read nothing the person could not read themselves.
- The project comes from the conversation, never from an argument. None of the input schemas has a project field, and none of the handlers looks for one, so a message that talks a model into naming another project has nothing to talk to.
The names are un-namespaced, like the platform's other built-in tools (load_skill, memory_remember, memory_forget) and unlike a provider's, which are namespaced "<service>__<tool>". A base tool is not one service's contribution, so putting a service's name on it would be a lie; and because every provider name carries the separator, a provider can never shadow one of these.
Index ¶
- Constants
- func MutatingToolNames() []string
- func PromptSection(withWritePath bool) string
- func Tools(opts Options) agentcore.ToolSet
- type AppliedResource
- type ApplyOutput
- type Condition
- type LocationView
- type LocationsListOutput
- type ManifestResult
- type Options
- type PlanOutput
- type QuotaGetOutput
- type QuotaRow
- type ResourceSummary
- type ResourcesGetOutput
- type ResourcesListOutput
- type SchemaGetOutput
- type ValidateOutput
Constants ¶
const ( // ResourcesListToolName lists a project's resources of one kind. ResourcesListToolName = "resources_list" // ResourcesGetToolName reads one resource whole. ResourcesGetToolName = "resources_get" // SchemaGetToolName describes the fields a kind accepts. SchemaGetToolName = "schema_get" // LocationsListToolName lists where a service is offered to this project. LocationsListToolName = "locations_list" // QuotaGetToolName reports what a project's allowance has left. QuotaGetToolName = "quota_get" )
The model-facing names of the read tools.
const ( // ResourcesValidateToolName checks manifests without keeping them. ResourcesValidateToolName = "resources_validate" // ResourcesPlanToolName settles what would happen and authorizes it. ResourcesPlanToolName = "resources_plan" // ResourcesApplyToolName carries out a plan that was agreed to. ResourcesApplyToolName = "resources_apply" )
The write path is three tools, of which exactly one changes anything.
resources_validate returns the platform's verdict and keeps nothing, so it is safe to rerun. resources_plan settles what would happen and returns the manifests plus a token hashing them. resources_apply re-derives that hash from what it was handed and refuses any mismatch.
Only a change already shown to the person who asked can reach the platform. See internal/plantoken for what the token covers.
Variables ¶
This section is empty.
Functions ¶
func MutatingToolNames ¶
func MutatingToolNames() []string
MutatingToolNames are the base tools on the change path.
resources_apply is the only one that writes. resources_plan is listed too because it alone authorizes a write, and an operator asking what this project's assistant can change wants both answers.
func PromptSection ¶
PromptSection is what the system prompt says about these tools. It is the same shape as the skills index: a short section, added only when the tools are present, so a turn without them never advertises them. The write half appears only when the change path was composed.
Types ¶
type AppliedResource ¶
type AppliedResource struct {
Action string `json:"action"`
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}
AppliedResource is one thing that was created or changed.
type ApplyOutput ¶
type ApplyOutput struct {
Applied []AppliedResource `json:"applied"`
// Next is the step from an accepted request to something actually
// running. They are not the same thing.
Next string `json:"next"`
}
ApplyOutput is what was done.
type Condition ¶
type Condition struct {
Type string `json:"type"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
Condition is one thing the platform reports about a resource.
type LocationView ¶
type LocationView struct {
Name string `json:"name"`
// Topology is everything the location declares about where it is — its
// city, its region, and whatever else the platform publishes. A selector
// that places by region is matched against exactly these keys.
Topology map[string]string `json:"topology,omitempty"`
// Ready reports whether the location is serving. A location can be offered
// yet not ready; the two are worth telling apart before promising anything
// will start there.
Ready bool `json:"ready"`
}
LocationView is one place a service is offered to this project.
type LocationsListOutput ¶
type LocationsListOutput struct {
Service string `json:"service"`
Locations []LocationView `json:"locations"`
// Note explains an empty list, so it is never read as a failure.
Note string `json:"note,omitempty"`
}
LocationsListOutput is where one service is offered.
type ManifestResult ¶
type ManifestResult struct {
// Index is this manifest's position in the list passed in.
Index int `json:"index"`
// Kind, Name and Namespace identify what it describes, where readable.
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
// Valid is false when the platform rejected it. Nothing can be planned or
// applied until the manifest is fixed.
Valid bool `json:"valid"`
// Errors are the rejections, each with the field path the platform named.
Errors []projectapi.FieldError `json:"errors,omitempty"`
// Exists decides between create and update.
Exists bool `json:"exists"`
// Action is "create" or "update".
Action string `json:"action,omitempty"`
// Diff is what applying would change about the existing resource, from
// what the platform said it would become. Empty for a create, and for an
// update that changes nothing.
Diff []string `json:"diff,omitempty"`
// Manifest is the canonical form. Present in a plan, where it is what the
// token covers and what apply must be handed back.
Manifest string `json:"manifest,omitempty"`
}
ManifestResult is what one manifest would do, and whether it can.
type Options ¶
type Options struct {
// Project reads and writes as the caller. Required — with no project view
// there is no identity to act as, and the tools are not built.
Project *projectapi.Project
// PlanTokenKey mints and checks the tokens binding a change to what a
// person was shown. Empty leaves the change path out: a service that
// cannot check a token must not issue one. See internal/plantoken.
PlanTokenKey []byte
// Logger receives operational warnings. Nil discards them.
Logger *slog.Logger
// Now is the clock, for tests. Nil uses time.Now.
Now func() time.Time
}
Options configures one project's base tools for one turn.
type PlanOutput ¶
type PlanOutput struct {
// Valid is false when anything was rejected. There is then no token and
// nothing can be applied.
Valid bool `json:"valid"`
// Results are in apply order, which the token covers.
Results []ManifestResult `json:"results"`
// PlanToken authorizes exactly these manifests in this order, and nothing
// else.
PlanToken string `json:"planToken,omitempty"`
// ExpiresAt is when the token stops being accepted, in RFC 3339.
ExpiresAt string `json:"expiresAt,omitempty"`
// Note carries anything about the plan the person should hear.
Note string `json:"note,omitempty"`
}
PlanOutput is what a person sees before agreeing, plus the token binding their agreement to exactly this.
type QuotaGetOutput ¶
type QuotaGetOutput struct {
Service string `json:"service,omitempty"`
Resources []QuotaRow `json:"resources"`
// Note explains an empty answer.
Note string `json:"note,omitempty"`
}
QuotaGetOutput is a project's allowance, one row per resource type.
type QuotaRow ¶
type QuotaRow struct {
// ResourceType is the platform's identifier, e.g.
// "compute.datumapis.com/vcpus".
ResourceType string `json:"resourceType"`
// Unit is what the numbers below count, e.g. "vCPUs".
Unit string `json:"unit"`
// Limit, Used and Available are in Unit, not in whatever the platform
// stores internally.
Limit int64 `json:"limit"`
Used int64 `json:"used"`
Available int64 `json:"available"`
}
QuotaRow is one resource type's allowance, in the unit a person reads.
type ResourceSummary ¶
type ResourceSummary struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
// CreatedAt is when the resource was first accepted, in RFC 3339.
CreatedAt string `json:"createdAt,omitempty"`
// Conditions is what the platform is currently reporting about it.
Conditions []Condition `json:"conditions,omitempty"`
// Labels are carried through because a placement, a selector or a
// provider's own tool is usually keyed on one.
Labels map[string]string `json:"labels,omitempty"`
}
ResourceSummary is one resource in a listing.
type ResourcesGetOutput ¶
type ResourcesGetOutput struct {
Kind string `json:"kind"`
APIVersion string `json:"apiVersion"`
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
// Manifest is the resource as YAML, with everything the platform owns
// removed — so it can be edited and handed straight to resources_plan.
Manifest string `json:"manifest"`
// Conditions is what the platform is currently reporting about it. Kept
// out of the manifest above, which is the desired state rather than the
// observed one.
Conditions []Condition `json:"conditions,omitempty"`
}
ResourcesGetOutput is one resource, whole.
type ResourcesListOutput ¶
type ResourcesListOutput struct {
Kind string `json:"kind"`
APIVersion string `json:"apiVersion"`
Namespace string `json:"namespace,omitempty"`
Resources []ResourceSummary `json:"resources"`
// Note says what was left out, when anything was.
Note string `json:"note,omitempty"`
}
ResourcesListOutput is every resource of one kind in the project.
type SchemaGetOutput ¶
type SchemaGetOutput struct {
Group string `json:"group,omitempty"`
Version string `json:"version"`
Kind string `json:"kind"`
// Path is the part of the kind this describes, when one was asked for.
Path string `json:"path,omitempty"`
// Schema is the description itself: the fields, their types, which are
// required, and what each is for.
Schema map[string]any `json:"schema"`
// Note says what was left out, when anything was.
Note string `json:"note,omitempty"`
}
SchemaGetOutput describes one kind's fields.
type ValidateOutput ¶
type ValidateOutput struct {
Valid bool `json:"valid"`
Results []ManifestResult `json:"results"`
}
ValidateOutput is the platform's verdict on each manifest.