is_airlock_api 0.21.0
is_airlock_api: ^0.21.0 copied to clipboard
The airlock's contract: the actions a tool describes, the trajectories they are proposed on, and the airlock that decides and records each one.
is_airlock_api #
The airlock's contract: types and their JSON, nothing that carries an
action out. Tools describe actions; the agent loop proposes each one
through the logbook; the airlock (is_airlock) decides it, writes its
decision to the logbook, and has a driver carry it out.
What an action takes and gives back, and the drivers that carry it out, are
is_effects's. 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.runOrFail(
file,
then: (wrote) =>
dart.runOrFail(Args(['format', file.path.value]), then: Done.new),
);
// `proposer` is the agent loop's: it writes each proposal to the logbook
// and waits for the outcome the airlock writes back.
var result = writeAndFormat(file);
while (result is Action<ExecResult>) {
result = await result.next(proposer);
}
A result #
Result<A>: what a tool returns for a call, whereAis its output type.Action(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 actions, 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 proposes nothing: an action's continuation is extended.action.next(proposer): the action proposed through aProposesActions, and the result it leads to.ProposesActionshas one method,propose(program, input), giving the action'sOutcome. The agent loop implements it over the logbook; a test can implement it directly.
An action #
Program: a closed set,ReadFile(Program.read),ReadFileBytes(Program.readBytes),WriteFile(Program.write),Executable(aProgramName, with plainArgs),FetchFromWeb(Program.fetch),MakeWebRequests(Program.makeWebRequests),AskTheModel(Program.askTheModel) andReplyToOwnConversation(Program.replyToOwnConversation).Action<A>: a program, its input and the continuation, all private. Made only by its program (program.run(input, then:),program.runOrFail), so its input is the program's own type.program.reachOf(input): what the input would do to the world, which the airlock decides and the logbook keeps:Reads(path, as:),Writes(file),Starts(program, args),FetchesFromWeb(fetch),MakesWebRequests(requests),CallsTheModel(call)orRepliesToOwnConversation(content).CarriesOutEachProgram: one method per program, each given that program's own input type, returning null when the machine cannot run it.program.carriedOutBy(by, input)calls the program's own method, so whoever carries programs out (the airlock, over its drivers) never casts, and a new program is a new method there that the compiler asks for.
The web #
FetchFromWeb(proposed asfetch) takes aWebFetch: an origin, aWebPath, a sign-in, and what of the response to keep (is_effects'sBodyToKeep). A proposal carrying a body or headers is rejected, not stripped.MakeWebRequests(proposed asmake-web-requests) takes the exactProposedRequests a tool built. A GET, a header other thancontent-type, an empty list, and a granted prefix named by the tool are all rejected when the proposal is read.- An
Allowfor either names the path prefix each request was granted under, one per request./grants the whole site.
A reply #
ReplyToOwnConversation(proposed asreply-to-own-conversation) takes aReplyContentalone: the model names no conversation and no sign-in. Its reach,RepliesToOwnConversation(content), holds the text and footer exactly.Allow.toReplyTo(endpoint, asSignIn:)grants theReplyEndpointthe docking station recorded for the trajectory and the sign-in a reply to it goes as, kept in the decision entry asgrantedReply. Its outcome is a list ofPostedMessages.
A model call #
- The loop writes what it will send to the logbook first: each text as a
ModelRequestPieceentry (kindmodel-request-piece,{"text"}), then aModelRequestFromPieces(kindmodel-request) naming them:systemPromptandrequest, each aTextFromPieces(its pieces in order and the sha256 of its UTF-8 bytes), andbuiltFrom, the turns they were drawn from.TextFromPieces.joinchecks the joined text against its hash. AskTheModel(proposed asmodel) takes aModelCall: theModelSignInNameit goes as, theModelName, and theModelRequestFromPiecesentry. Its reach,CallsTheModel, is decided by the sign-in.
Decisions #
- A
DecisionisAlloworDeny(why), each saying who made it (DecidedBy);Allow.byis null when no rule governs the reach.reliedOnnames the logbook entries the airlock read to decide beyond the rules. AirlockDecisionOnAction.toJson/fromJson: a decision of every reach as the logbook holds it (kindairlock-decision-on-action), its reach written as the program and input that make it, naming the proposal it answers.
Between the agent loop and the airlock #
The logbook is the only channel between them: the airlock has no door of its own.
program.proposal(input, at: place): the body of anaction-proposed-by-agent-looplogbook entry. It names no trajectory: the airlock takes the path from the chain the entry is on, which only the path's loop user writes.ActionProposedByAgentLoop.read(body)gives anActionProposedByAgentLooporRejected(why), checking every part as its type's ownparsedoes.proposal.open(<I, O>(program, input) => …)hands back the program and its input with their types matched.PlaceInTrajectory, sealed:ProposedForTheModelCall(turn), written[turn, "model-call"];ProposedForAnIntent(turn, intent, action), written[turn, intent, action]; orProposedForTheReply(turn, action), written[turn, "reply", action], in that order within a turn.parsegives null for anything else.- A result (kind
outcome-of-proposed-action, body{"proposed": <hex>, "result": <outcome>}):program.outcomeToJsonwrites the outcome andprogram.outcomeFromJsonreads it back;outcomeOfProposedActionToJson(proposed, resultAsJson)writes the body,proposalRejectedToJson(proposed, why)answers aRejectedproposal, andreadOutcomeOfProposedAction(body)reads one back as(proposed:, result:), or null. WaitingToStart(kindwaiting-to-start,{"trajectory": <hex>}): loop_launcher writes it once, on a chain of its own, when a path with noassignedentry yet has to wait for room.LoopUser(loop-<n>) andSuit(suit-<n>): the OS users loop_launcher hands each path, written in itsassignedentry.
What this package holds #
Types and their JSON. Two tests hold it there: one reads every directive's
URI from Dart's parse tree and allows only the vocabularies and
is_effects; the other finds every async function body in lib and
allows none, since waiting on something is carrying an action out.