is_airlock_api 0.5.0
is_airlock_api: ^0.5.0 copied to clipboard
The airlock's contract: the runs a tool describes, the journey paths they are proposed on, and the airlock that decides and records each one.
is_airlock_api #
The airlock's contract. Tools describe effects; the airlock decides and
records each one; drivers operate the world. A tool touches nothing: for
each call it returns a Result, which is followed on a journey path.
What an effect takes and gives back, and the drivers that carry it out, are
is_effects's, so a driver never sees this package. Joining an
is_tools_api definition to what a tool does is is_tool's.
final dart = Executable.parse('dart')!;
/// Writes [file], then formats it.
Result<ExecResult> writeAndFormat(FileText file) => Program.write.runOrRefusal(
file,
then: (wrote) =>
dart.runOrRefusal(Args(['format', file.path.value]), then: Done.new),
);
// The airlock service's side of a journey path the docking station started;
// the airlock service holds the drivers:
final journeyPath = JourneyPath(
id: JourneyPathId.of(startEntry), // the hash of the entry that started it
drivers: [files, programs],
airlock: airlock,
rules: rules,
);
// Its loop, for one tool call, at that call's place in the turn:
final apex = journeyPath.at(place);
var result = writeAndFormat(file);
while (result is Run<ExecResult>) {
result = await result.next(apex);
}
A result #
Result<A>: what a tool returns for a call, whereAis its output type.Run(do this, then hand what happened to the continuation),Done(value)(the answer), orFailed(why)(it couldn't).Failedis aResult<Never>, so one fits every tool. A tool may take several runs, with ordinary logic between them; each is decided on its own.result.map(f): the same result with its answer, once there is one, given tof. It reaches no driver: a run's continuation is extended, so every run is still decided and recorded at an apex. Turning a tool's answer into what the model is told takes no journey path.
A run #
Program: a closed set,ReadFile(Program.read),WriteFile(Program.write),Executable(aProgramName, with plainArgs) andWebSend(Program.web, aSendto anOriginthrough a namedSignIn). Programs reach drivers, so they belong with the drivers and the airlock to what is trusted; a new kind of effect is a new driver and program.Run<A>: a program, its input and the continuation, all private. Made only by its program, so its input is the program's own type. Nothing about a run shows outside; when it is proposed, what it would do is worked out as itsReach, which the airlock decides and records:Reads(path),Writes(file),Starts(program, args)orSends(send, renderer). A rule grants a send by origin and sign-in together.
A send #
Everything a send says is drawn from recorded journal entries, by a renderer the record names exactly (https://github.com/enspyrco/intersyntactic/issues/1147).
Send: origin, method, aWebPath, sign-in, headers, aRendererNamesuch asteams-reply, and theEntryIds of the recorded entries its words are drawn from. It has no body, so a tool cannot put words in. The path and headers are checked as is_effects'sRequestchecks them.Airlock.renderer(name)resolves a name to aRenderer: itsRendererId(the sha256 of the renderer's published pub archive, aspubspec.lockrecords it) and theObjectIdof the render runner built with it, which pins the packages the renderer depends on as well. It is resolved before the decision, soDecidedholds the wholeSendand the exactRenderer, never a body, which does not exist yet. A name that resolves to nothing is denied before the rules are asked.- The airlock never talks to a renderer
(https://github.com/enspyrco/intersyntactic/issues/1147#issuecomment-6905923566).
A renderer follows the journal for
Decidedentries naming it, reads the entries the send draws from, and records the body, or a refusal when an entry is missing, in an entry of its own after theDecided.Airlock.rendered(decided)is the airlock following the journal to that entry; it is called only onceDecidedis kept, and what it gives is what is sent. So the exact bytes sent are in the record. - A send's chain in the journal:
DecidedSend(kindsend-decided), then the renderer'sRendered(kindrendered), then the airlock'sReturned, each following the one before, so the journal's tip check lets each be written once. When the renderer does not answer in time,Returned(refused) follows theDecidedSenddirectly and a lateRenderedis turned away. Each hastoJsonand a checkingfromJson. What came back from any proposed run is recorded in full, in aReturnedProposal(below).
A send is an effect, decided like any other: what a tool sends to a chat or an API. A journey path's prompts are not: the model is the agent planning, so a prompt is not decided, and no tool is in it. How a prompt is sent and recorded is not this contract's.
A journey path #
One agent's own journey: its id, its rules R, and its airlock and
drivers. Its drivers act for the path, each wherever it runs.
Every entry it records is at a place P in a turn, which the agent loop
supplies and the airlock records; nothing here computes one.
JourneyPath(id:, drivers:, airlock:, rules:, suit:): the airlock service's side of a journey path, set up when the record shows the docking station started the path (its rules, inadmitted) and loop_launcher handed it users (assigned). The airlock starts nothing. Holding the drivers is already the power to touch the world, so setting up a side grants nothing new.at(place): the journey path's apex at that place, its tip, where its agent loop proposes the next run and its airlock decides it. The journey path checks the place's type, so whatever follows a tool's result takes anApexand never handlesP. Two agents on one machine have two apexes; one step's two tool calls are two apexes of one journey path, at two places.JourneyPathId, fromis_shapes: a journey path is named by the hash of the record entry that started it (JourneyPathId.of(entryBytes)), which the docking station writes, the way aJourneyIdnames a journey. So no two journey paths share an id, after a restart too, and nothing here mints one. Every entry names it.run.next(apex), the only way a run reaches the world: it is proposed at the apex, and the airlock decides it; the airlock records the decision (Decided) and only then is a driver reached; the run comes back and the airlock records it (Returned), and only then does the continuation see it. A record that cannot be written ends the call. ADecidedwith noReturnedis a run cut short. Recorded means it survives the journal crashing, not a power cut (https://github.com/intersyntactic/journal/pull/12).- A
DecisionisAlloworDeny(why), each saying who made it,DecidedBy.rulesorDecidedBy.person; a stopped journey path's refusal is the person's. stop(): refuses every run on this journey path whose driver has not yet been reached. A run whose driver has been reached is not interrupted.entries: each entry once recorded, at its place.underway: what drivers report while a run is underway, for a live view, and not recorded. Each names its journey path and place.Airlock<R, P>:decide, given a run'sReach, andrecord, implemented by intersyntactic's airlock.
Between the agent loop and the airlock #
The agent loop and the airlock are separate services, and the record is
the only channel between them: the airlock has no door of its own
(https://github.com/enspyrco/intersyntactic/pull/1156). A run's
continuation is the tool's own code, so it stays in the loop; its program
and input go into the record as a Proposal, an effect not yet decided,
and what came back returns through the record
(https://github.com/enspyrco/intersyntactic/pull/1157). The airlock decides
and records, and only a driver carries an effect out.
JourneyPath.at(place)is an apex where the journey path is, in the airlock service.Apex.through(link, place:)is one in the agent loop, over aRecordLink, the transport, which this package does not have: it writes aproposedentry on the loop's journey path's chain and waits for thereturnedentry that names it, which loop_launcher hands the loop.run.next(apex)is the same with either, so a tool does not change.- A
Proposal(kindproposed) names no journey path. The journal takes the entries on a path's chain only from that path's loop user, so the airlock takes the path from the chain the entry is on, and a loop has no claim to make about another path. Until the journal enforces that, the airlock must not act onproposedentries. Proposal.read(json)gives aProposalorRejected(why), checking every part as its type's ownparsedoes, with is_effects's codecs.journeyPath.consider(proposal, place, proposed: entryId)decides and records it as a run proposed atat(place)would be; itsDecidedandReturnedname theproposedentry.ReturnedProposal(kindreturned): what came back from a proposed run, in full, as the program's codec writes it, or the refusal, naming theproposedentry it answers. It is the one copy of what an effect returned: a read's text, a program's output, a site's answer. The airlock writes it on its own chain, never the path's, which only the loop user writes.ReturnedProposal.of(returned)makes one from aReturnedentry;ReturnedProposal.refused(entryId, why)answers aproposedentry that wasRejected, so its loop is answered and no other path is held up.LoopUser(loop-<n>) andSuit(suit-<n>): the OS users loop_launcher hands each path from pools infra makes ahead of time, and records in the path'sassignedentry. The path's loop runs as its loop user, and its programs run as its suit, the identity the path wears, contained or open (https://github.com/enspyrco/intersyntactic/pull/1158): the airlock service gives the path a program driver that runs as it.- An answer the loop cannot read as an outcome throws a
FormatExceptionand ends the call: whether the run reached the world is then known only to the airlock's record. - Progress (
underway) stays in the airlock service; anyone who subscribes to the record sees the entries.
A journey path is not narrowed from another. For one agent to do less than another in the same journey (a reviewer that reads while the crew writes, https://github.com/enspyrco/intersyntactic/issues/1049), the plan is that it would be started with fewer rules, its starting entry naming its parent and its rules, so the airlock could check they are no wider. It would still be named by that entry's hash: a child names its parent, the way a git commit does, never the other way round. None of that is built: today the docking station gives a journey path whatever rules it likes.
What the contract does not promise #
An airlock guards the drivers it is given, not the journey. An agent that joins a journey with its own drivers and its own airlock, or none, is outside it. So "every effect through these drivers is recorded" holds, and "every effect in the journey is recorded" is not this package's to promise; the journey's rules bound our journey paths, not anyone else's.
The library imports is_effects, is_shapes and is_content_id and
nothing else outside the SDK; a test reads every directive's URI from Dart's parse tree and
holds it to that.