Class TargetRuntime
- Namespace
- IntentSharp.Targets
- Assembly
- IntentSharp.dll
Runs AI operations against one ITarget: it senses the target, plans a command with the model, checks the command against the rule files at the Data checkpoint and executes it only when the check passes. The same runtime serves any technology; the target supplies everything the technology needs.
public sealed class TargetRuntime
- Inheritance
-
objectTargetRuntime
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
One operation runs in order: sensing (probe the target and describe it when the probe's token changed, or every
time without a probe), a check with data.stage sense, planning (the plan intent, a default intent
document a developer or a model may replace in the client's document store, with the description, the request and
the target's guidance as input and the target's command schema in its output schema), an inspection and a check on
every planning attempt with data.stage plan (violations and refusals go back to the model, which tries
again within the plan intent's attempts), and the execution after a fresh check with data.stage
execute. When the target throws a TargetOperationException with
SchemaMismatch, RunAsync(string, object?, CancellationToken) describes the target again and plans once
more within the attempts the first plan left.
The checks fail closed. With no rule set named here or on the client, every operation is refused, and so is every
operation that names a set written for another target (a set whose Target is set and is
not Name). A plan that failed or gave no command is refused as "nothing was checked", and so is
every plan while no version of the plan intent loads, and every command whose inspection names no operation, or names
an operation and no entity without TouchesNoEntity. The command a target executes is
the one copy of the plan its inspection read. A version loads here only when its output schema is inline or
IntentSharp.Documents.Core.DefaultIntentDocument.CommandPlanSource, the one source this runtime builds; a stored version that does
not load leaves the last one that did running. The target's own refusals always apply. A command
whose inspection names any operation but read runs only when data.allowWrites resolves to true, and
what the command may touch is decided by the data.entities and data.operations rules, never by this
class. Settings resolve the file's value first, then Settings, then the library
default, or the fail-closed value for a security setting.
Limits: the execution runs under the resolved data.timeout, which the runtime enforces itself, sub-second
values included, so a target that ignores Limits still stops at the limit; and the
records are cut to the resolved data.maxResults. Only unlimited written in a file, or set in code,
removes a limit.
Change detection: each new description is fingerprinted and compared with the fingerprint the client recorded in its
document store's state (env/<target>), so a schema changed while the application was stopped is found at
the next start. A difference is an EnvironmentChange: the client's
IEnvironmentChangeHandlers run before the operation continues, the change is checked at the
Environment checkpoint with this runtime's rule sets, and a refusal there refuses
the operation. While a rule set this runtime names is pending (a handler reported it with
ReportPending(string, string?) and it has not caught up), every operation is checked at the
Environment checkpoint again after it senses, with environment.pendingRecompile counting its pending sets, so a
rule such as count max 0 refuses operations until the rules catch up. The target is described again when its
probe's token changes, when its GetChangeToken() fired since the last description, and after a
schema mismatch. Before it
senses, an operation waits for the handlers of changes the client found in the background (a document, the provider
options), which are checked at the Environment checkpoint with the client's default sets and the sets of every target
runtime created over the client, and its Maintenance reports what every handler it waited for did;
PlanAsync(string, object?, CancellationToken), CheckAsync(CommandPlan, CancellationToken) and DescribeAsync(bool, CancellationToken), which return no outcome, and an
operation that throws leave that for the next operation that does. A change found during an operation is handled to
the end even when the operation is cancelled meanwhile: the operation throws, and the next one reports the change.
While the model's reply is checked, the runtime waits for InspectAsync(TargetCommand, TargetContext, CancellationToken) and the guardrail check without yielding, so an inspection should not need I/O. Any exception the inspection or the check throws while a reply is checked becomes a problem the model sees, so a target's inspection should refuse, not throw. A runtime is safe to share between threads.
Constructors
- TargetRuntime(IntentClient, ITarget, TargetRuntimeOptions?)
Creates a runtime over
targetthat plans withclient.
Properties
- Target
The target this runtime operates on.
Methods
- CheckAsync(CommandPlan, CancellationToken)
Checks
planas it would be checked before it runs, withdata.stageplan: the target inspects it and the rule sets judge it. No model is called and nothing is executed.
- DescribeAsync(bool, CancellationToken)
Returns the target's description, with its Fingerprint: the one already received when the target's probe returns the same token as then and its change token has not fired, else a new one from DescribeAsync(TargetContext, CancellationToken). A target without a probe is described on every call. A new description whose fingerprint differs from the recorded one is an EnvironmentChange, handled before this returns with this description and checked with this runtime's rule sets, as during an operation; the next operation reports what the handlers did, and a refusal of the change's Environment check refuses it.
- ExecuteAsync(CommandPlan, CancellationToken)
Checks
planand, when the check passes and a fresh check withdata.stageexecutepasses too, runs it on the target under the resolved limits. A refused plan returns an outcome with Executed false; so does a dry run (data.dryRunresolved to true). The plan is copied once, when the call starts: the target inspects that copy and executes that same copy, so a change made to the plan's command or parameters during the call never reaches the target. Plan holds the copy.
- PlanAsync(string, object?, CancellationToken)
Senses the target and asks the model for a command for
request, checking each reply on the way. Nothing is executed. When the check withdata.stagesenserefuses, no model is called and the result is unsuccessful with one Guardrail issue.
- RunAsync(string, object?, CancellationToken)
Runs one whole operation for
request: sense, plan, check and execute. Writing a record is the same call with the record asinput; whether it may write is decided by the rule files and thedata.allowWritessetting. A refused check or a failed plan returns an outcome with Executed false and Check saying why.