Agent Runtime Input and Normalized Output
Status: 2026-11-14. Built: RunInput, Result, the Trigger decisions, progress, questions, sends, and the Host's normalized Output kinds as defined in pkg/plugin/types.go and used by
Status: 2026-11-14. Built: RunInput, Result, the Trigger decisions, progress, questions, sends, and the Host's normalized Output kinds as defined in pkg/plugin/types.go and used by plugins/agent and internal/host/engine. Proposed: channel metadata, session keys, history by token budget and the decision reset (P29, channel context), the reply format (P15, context), steering input (P6), and the protocol adapters of section 7. This document defines what the Agent Runtime receives and what it produces; the loop between them is in the execution kernel.
1. The Boundary
flowchart LR
T["Transport<br/>Submit(Event)"] --> G["Trigger<br/>Match → Decision"]
G -->|start| H["Host<br/>run · CallContext · pinned generation"]
H -->|"Execute(RunInput, RuntimeHost)"| R["Agent Runtime"]
R -->|"Progress (ephemeral)"| H
R -->|"Ask · Send (durable)"| H
R -->|"Result{Text, Artifacts} or error"| H
H -->|"Output: progress · final · error · question · notice"| P["Presentation → Delivery"]The agent never learns delivery details. It returns text and artifact references; the Host builds an Output, the connection's Presentation turns it into channel Items, and Delivery sends each one with an idempotent Delivery.ID. A failed delivery is retried on its own and never re-runs the agent (TestDeliveryRetryNeverRerunsRuntime). A Presentation that fails gets a plain text item (plugin.TextItem) in its place, which every Delivery accepts; one that returns no items and no error chose to show nothing, such as a channel that cannot edit what it sent being told that a question was settled, and nothing is sent (2026-11-29, TestAPresentationMayShowNothing).
2. RunInput
| Field | Source | Meaning |
|---|---|---|
RunID, Attempt | Host | The run and its attempt number (1 on the first start) |
Conversation | Transport event, kept by the Host | Chat id, direct or group, thread, and the source message to reply to |
Principal | Host identity | ID, Tenant, User, Connection, ExternalID, Name, Role; never taken from a payload |
Text | Trigger decision Text, or the event text | The input message |
Attachments | Event attachments, fetched by the Host through the Transport's Fetcher | Artifact references; the agent turns them into image or file parts of the input message. A file that cannot be fetched is left out, and Text ends with a note naming it and the reason, saying an older file of the same name is not it and asking to tell the user (Feishu report #68) In a group, a message that starts a run with no attachments of its own takes the files its sender sent alone (without a mention) in the same chat and topic in the last 10 minutes, each once: a Feishu topic group cannot put a file into an @-message (Feishu report #72). |
History | Host | Built: the last history_turns (default 10) succeeded runs of the conversation, as {User, Assistant} text pairs, oldest first. P29: the succeeded runs of the session key after the last /new, within history_tokens (default 12,000), with a start that moves only in jumps; each Turn also carries Speaker, At, MessageID (section 2.1) |
Checkpoint | Host | The agent's last saved state, set when an attempt resumes |
SessionState | Host, from Result.SessionState of the session's last successful run | Opaque to the Host (ADR 0021 part 1, context refactor slice 4, 2026-12-04): the agent's transcript, which its next run extends. Kept per session and runtime instance in session_states, replaced in the transaction that records a successful run, never stored with the run's result; empty for a new session and after the session closed, a message of it was removed or a person who wrote in it was forgotten. Session.Shared marks a session several people share, for which the agent keeps none |
Locale | The connection's locale | The language of texts the agent shows people itself, such as approval prompts |
Skill | Trigger decision Skill | A skill the user invoked as a command |
Channel (P29) | Host | Transport plugin name of the connection (feishu, console, httpapi) |
Message (P29) | The event that started the run, stored on the run row | *InputMessage{ID, SentAt, Mentioned, Mentions, Quote, Meta}; Meta holds channel facts by namespace, with the Trigger's Decision.Meta merged in (P47) |
Fields (P47) | Host, from the manifests of the transports and triggers routed to this runtime instance | The context_fields declarations; the same for every run of a generation (channel context, section 3) |
Chat (P29) | Host, from ignored ambient events of the session, stored on the run row | []ChatLine{MessageID, Sender, SentAt, Text, Files, ReplyTo}, oldest first, at most 20 |
ChatTruncated, HistoryTruncated (P29) | Host | Older chat lines or runs exist that are not shown |
Format (P15) | The presentation instance's FormatNote() | One English sentence on how replies are rendered |
The run's trusted context is also in RuntimeHost.Context() as CallContext (run, calling instance, principal, conversation, connection, call chain). The input carries no tool grants, delivery targets, credentials, or system prompt text. The reply language follows the user's latest message; the timezone comes from the agent's timezone setting, not from the locale.
Image parts reach the model only if its instance accepts images; otherwise the Host replaces each part with a text line naming the file and its artifact id (internal/host/engine/content.go).
The agent renders these fields into the run-context message (<orq:context>, <orq:chat>, <orq:quote>); the field list is in context, section 3.1.
2.1 Event and Turn Fields (P29)
Optional fields that transports fill and the Host carries; the Feishu sources are in channel context, section 2.
| Type | New field | Meaning |
|---|---|---|
Conversation | Title | Chat title; written by people, untrusted |
Event | SentAt (built 2026-12-01) | The platform's send time, when the transport knows it (the Feishu bot and twin fill it). The Host stores it on the message's session entry (UserEntry.SentAt); the agent orders the group chat window and a conversation_log page by it and shows it, since a channel may deliver messages in another order |
Event | Mentions []Mention{ID, Name, IsBot, IsYou, All} | Mentions in text order; Text shows them as @Name |
Event | Spans []TextSpan{Start, End, Kind, ID} (built, P84) | Byte ranges of platform entities in Text, such as mention; the sigil parser treats them as plain text. Feishu fills them for other people's mentions |
Event | Quote *Quote{MessageID, SenderID, SenderName, FromYou, Text, SentAt} | The message this one replies to, text ≤ 2,000 characters. Built today: Quote{ID, Sender, Text, FromSelf}; FromSelf (2026-12-01) marks a quote of the assistant's own message (the Feishu bot by its app id, the twin by its marker or sent ids), rendered sender="Orquelo (an earlier reply of yours)" |
Event | Ambient | A group message not addressed to the bot; ignored ones form the chat window |
Event, RunInput | Context *ChannelContext{Lines []ContextLine{ID, Sender, Text, SentAt, Assistant, Root}, IDs, Omitted} (built 2026-11-29) | Earlier messages of the conversation the Transport sends with a request, oldest first, such as the thread a Feishu twin /dt was sent in: its default context. The Host keeps them on the run row (runs.context) and passes them to whichever runtime runs it. pkg/convcontext renders them and the Quote as one text, the same for every runtime (the agent's run context, an external CLI's prompt, a workflow's task): <orq:chat> with a note that the context may be incomplete and the runtime should look at its own tools to get more, an earlier reply of the assistant (Assistant, such as the twin's, sent from the owner's account) shown as Orquelo (an earlier reply), and the chat, thread and message ids, with IDs, the channel's guidance on what kind of ids they are when they are not its usual ones (the Feishu twin's web client ids), as ids; then <orq:quote> |
Sender | Name (exists) | Filled by Feishu from the contact API; updates Principal.Name (built in internal/host/identity) |
Turn | Speaker Sender, At time.Time, MessageID string | Who wrote the history message and when; the agent renders a header [name · id · time] |
A transport that fills none of them behaves as today.
2.2 Removed Messages (built 2026-12-01)
A Transport tells the Host that the platform removed (recalled, deleted) an earlier message by submitting an Event of another type through the same Submit (context review F-12). Event.Type is message for a message someone sent, or:
Type | Field | Rule |
|---|---|---|
message_removed | Subject | Required: the id of the removed message, the ID its own event was submitted with |
Conversation.ID | Required: the chat the message was in. Kind and ThreadID are not read: a platform need not say them (Feishu's recall event does not) | |
ID | Required: the removal's own dedupe key, different from the message's (Feishu: <message id>:removed); a repeated ID on a connection is admitted once | |
Sender | Optional: a platform need not say who removed the message. The event resolves no principal and runs as nobody | |
| every other field | Ignored |
- ◆Who may send it. The connection's own Transport, as for every event; it reaches only what that connection stored.
- ◆What the Host does. In one transaction it blanks every
user_messageandambient_messageentry whosemessage_idequalsSubject, in every session of that connection and conversation, a thread's and a sender's included: the payload is emptied and the entry flaggedtombstoned, as/forgetdoes, and each summary or digest written after it in its session is flaggedstale. The conversation's other open sessions read the message from the group's log without storing it, such as a member's own session withsession_scope: sender: their summaries and digests written since are flaggedstale, their saved state is dropped and their content version rises, so their runs rebuild (2026-12-05, review #264 H18). It opens no session, calls no Trigger, starts no run, sends nothing, and the event is no line of the chat. The inbox row endsignoredwith the notemessage_removed:<entries blanked>. - ◆What the model sees. The line leaves
<orq:chat>andconversation_log; a removed request stays in the history as(This message was deleted.), with the reply it got. - ◆Idempotent. A second removal, or one for a message the Host never stored (or stored on another connection or in another chat), changes nothing and is logged at debug (
message.remove_unknown); a removal that blanked something logsmessage.removed. - ◆Failure.
Submitreturnsevent.invalidwithoutID,Conversation.IDorSubject; the Transport decides whether its platform sends the event again. A failed transaction is retried as any routing is, up to 5 attempts. - ◆Limits. A run that already started keeps the text it was given; what the assistant answered and what its tools returned stay; the inbox row of the original event keeps its body. A removal routed before its message (the message's routing failed and is being retried) finds nothing. An edited message is not tracked:
message_removedis the only change type, since no built transport has an edit event (the Feishu SDK has none).
Transports: the Feishu bot submits it for im.message.recalled_v1, the Feishu twin when a message it submitted is pushed again as deleted (plugins/feishu/removed.go). Tests: TestRemoveMessage, TestRemovedMessageLeavesTheSession, TestChatWindowSkipsARemovedLine, TestBotRecallSubmitsARemoval, TestTwinDeletedMessageSubmitsARemoval.
3. What the Trigger Decides
| Decision | Effect |
|---|---|
start | Creates a run with Text (or the event text) and an optional Skill. If the conversation has an active run, the new run is queued and starts after it; its History then includes the earlier run if it succeeded. |
cancel | Requests cancellation of the conversation's active run. |
answer | Answers the conversation's pending free-text question with the event text. |
reply | Replies with Text without a runtime. |
ignore | Drops the event. With P29 the inbox keeps an ignored event marked Ambient for the chat window. |
reset (P29) | Starts a new session: the Host records a boundary for the session key, so later runs get no history or chat lines from before it, and replies with the notice session.reset. An active run continues. The chat trigger maps /new to it; text after /new (Decision.Text) then starts a run (P84). |
steer (P6) | Section 8. Steering carries text only: when the event has attachments, the Host starts a run for it instead (queued behind the active run), so the attachments are fetched as for any run (Feishu report #34, 2026-11-17). |
feedback | A report for the operator (built 2026-11-17): Kind is bug (the default), suggestion (product suggestion) or architecture (architecture improvement). The Host stores the kind, Text, the event's attachments and the conversation's last three runs (internal/host/feedback), replies with the notice feedback.received.<kind> and its number (one numbering for every kind), and starts no run. The chat trigger maps /bug <text>, /suggest <text> and /arch <text> to it, also while a run or a question is pending. From a run's shell, orquelo feedback submit [-kind K] "text" files the same report for the run's person and chat, which ORQUELO_RUN names (Feishu #226, 2026-11-26); from an operator's terminal the report is the operator's and has no chat. The operator reads reports with orquelo feedback list [-kind K]|show and closes one with orquelo feedback close N "note"; the Host then sends feedback.closed to the reporter's conversation once. The report records who closed it, shown by feedback show: from the agent's shell the run's person and run, from a terminal the local CLI and its operating system account (Feishu #195). |
The Trigger sees ActiveRunID, PendingQuestion, the Host's one resolution of the text in Sigils, and the directives visible to the sender in Directives (P84, sigils); a decision's Skills, Command and Tool must match the resolution, or the Host refuses it with the notice sigil.refused. With P29, ActiveRunID and PendingQuestion are those of the event's session key (<conversation_id>, plus /t:<thread_id> in a thread, plus /u:<principal_id> with the connection option session_scope: sender); runs of one conversation still run one at a time. A card click answers through TransportHost.Answer with the QuestionView id and version instead of a Trigger decision.
4. What the Runtime Produces
| Runtime action | Host output | Delivery |
|---|---|---|
Progress(text) | Output kind progress; one channel message updated in place (UpdateRef), at most once a second. The progress, final and error outputs also carry Output.Progress, the run's latest structured view (ADR 0022), and Output.Task, what the run was asked, for a Presentation that lays out cards (terminal UI T6) | Best effort, not stored |
ProgressView(view) (built 2026-12-04, ADR 0022) | The same progress as data: todos, steps with their state and result, the streamed text, usage. Kept in memory while the run runs and offered to the person's app clients (ClientHost.RunActivity, WatchActivity), at most every 100 ms | Best effort, bounded, not stored |
Ask(question) | Output kind question with a QuestionView and the question's files in artifacts, to the run's conversation or to Question.Target | Durable |
Send(key, to, text, artifacts) | Output kind final to another target the instance's targets allow | Durable, once per key |
A tool's Notify(key, text) (plugin.NoticeHost, optional on ToolHost) | Output kind final to the run's principal's direct chat on the run's connection (the run's own conversation when that is the direct chat); no targets grant, since it reaches only the person the run works for | Durable, once per tool instance, key and run |
Return Result | Output kind final with Text and Artifacts; UpdateRef names the progress message, so a Presentation may render into it | Durable, queued in the run's final transaction |
| Return an error | Output kind error with a localized text (run.failed, run.refused, run.run_limit, run.daily_limit) | Durable |
| Cancelled or timed out | notice (run.cancelled) or error (run.timeout) | Durable |
The files of an Ask, a Send or a Result are only those the run may open: its own artifacts, its attachments and its session's files; another run's artifact id is dropped and logged as artifact.not_the_runs. Each Item a Presentation returns carries in files the artifact ids of its Output, set by the Host, and a Delivery's OpenArtifact opens those and no others (Feishu #252, 2026-11-28).
The agent's progress text is composed in plugins/agent/progress.go: the todo list with status marks, the text the model is streaming in the current Step, and one line per tool call (· name args). Progress stops before the final output is sent, so a late progress update never overtakes it. A Delivery that cannot update the message an item replaces sends the item anew and withdraws the old message, so one message remains; the Host then updates the new progress message (Feishu: one more try after a second first, Feishu #225, 2026-11-26).
5. The Final Result
type Result struct {
Text string `json:"text"`
Artifacts []ArtifactRef `json:"artifacts,omitempty"`
}- ◆
Textis the final answer, prefixed by any text that was cut by the output limit and continued. An empty answer without artifacts becomes the localizedagent.no_answer. - ◆
Artifactsare all artifacts that tool results returned during the run, for example files published with theartifacttool oflocalenv. Working files in the workspace are not listed. - ◆A failed, cancelled, or timed-out run delivers no
Result: its artifacts are not sent, and the progress message already shown stays. The user receives the error or notice instead. - ◆Token usage is not in the result. The Host meters it per run and person in
Chatand logs it withmodel.called.
6. Traces
Success with one tool. (1) The Trigger returns start; the Host creates the run and calls Execute. (2) The agent gathers context items, skills, and the pinned tools, and calls the model; streamed text appears as progress. (3) The settled response proposes read; the agent checkpoints and calls CallTool with key m1:call_1; the ledger records started, then done. (4) The agent checkpoints the tool message and calls the model again; the final answer passes the completion checks. (5) The Host records succeeded and queues the final output in one transaction; Delivery sends it.
Approval across a restart. (1) The model proposes bash, which localenv marks for approval. (2) CallTool finds no granted reviewer that decides, opens the question approve:m1:call_1, and the run becomes waiting. (3) The Host restarts. Recovery requeues the run because it was waiting. (4) The resumed attempt finds the pending call in the checkpoint and calls CallTool with the same key; Ask returns the same question. (5) The requester clicks approve; the call runs once and the run continues.
Question answered from another conversation. (1) A tool plugin asks with Question.Target set to the requester's direct chat (Self), which the runtime instance's targets: [self] allows. (2) The question is delivered there. (3) The requester answers in the direct chat; the Trigger's answer decision settles it, and the blocked call continues in the group run.
Failure. (1) The model plugin returns an error after streaming began. (2) Execute returns the error. (3) The Host records failed and delivers a localized run.failed notice naming the run; no step is replayed, and no target re-runs the agent.
Cancel. (1) The user sends a stop message; the Trigger returns cancel. (2) The worker cancels the run's context; the agent's blocking call returns. (3) The Host records cancelled and sends run.cancelled, even if the runtime returned a result at the same moment.
7. Mapping to External Agent Protocols
An adapter is a Transport or Presentation plugin, never part of the agent. plugins/httpapi already exposes runs to HTTP clients through RunForEvent and CancelRun. The other adapters below are proposed; the protocol versions and sources are recorded in the agent runtime review.
| Orquelo | AG-UI 1.0 | Agent Client Protocol v1 | A2A 1.0 |
|---|---|---|---|
| Progress text | TEXT_MESSAGE_CONTENT | agent_message_chunk | artifact_update with append, or a status message |
Final Result.Text | TEXT_MESSAGE_END, MESSAGES_SNAPSHOT | None in v1; agent_message in the v2 draft | message with the agent role |
| Approval question | RUN_FINISHED with outcome interrupt; a new run carries the response | session/request_permission | Task state INPUT_REQUIRED or AUTH_REQUIRED |
ask question | An interrupt with a response Schema | elicitation/create | INPUT_REQUIRED; the answer is a new message on the same task |
Result.Artifacts | None dedicated | Resource content blocks | Artifact, artifact_update |
| Run started, succeeded, failed | RUN_STARTED, RUN_FINISHED, RUN_ERROR | The prompt response's stop reason | status_update with the task state |
AG-UI ends a run when it needs a person and resumes in a new run, while an Orquelo run stays open and waits, so an AG-UI adapter maps one Orquelo run to several AG-UI runs. Tool calls, the todo list, and usage are reported as typed progress, ProgressView (ADR 0022, built for the terminal UI); an adapter can use it.
8. Proposed Input Addition: Steering (P6)
Today a message sent while a run is active becomes the next run. Steering would let a Trigger add it to the active run instead: a new Trigger decision steer stores the text on the active run, and the agent reads it with RuntimeHost.Steering(ctx) ([]string, error) before its next model call, after settling pending tool calls. Each message is returned once and is part of the checkpointed messages after that. A process runtime reaches the same method over JSON-RPC. This changes pkg/plugin and the Host and needs an ADR.
9. Compatibility and Limits
- ◆The contract is the Go types in
pkg/pluginand their JSON form, which process plugins use over JSON-RPC (pkg/plugin/rpc). The manifest declaresapi: v1. Adding an optional field is compatible; removing or redefining one needs a newapiversion and a migration note. - ◆The agent's checkpoint has its own
version(currently 3: version 2 added the prompt pin, version 3 the compaction fields of P5). It reads versions 1 and 2 as version 3; a resumed attempt with any other version fails instead of guessing (compaction, section 7). - ◆Error codes are stable (
agent.limit,agent.loop_detected,agent.model_stopped,run.timeout,input.denied, ...). People see texts rendered from message keys inzh-CNoren-US; nothing parses translated text.
10. Acceptance
- ◆Built:
TestAttachmentsBecomeParts,TestContextItemsComeBeforeTheInput,TestInvokedSkillLeadsTheTurn(plugins/agent);TestFreeTextQuestionAnsweredByReply,TestApprovalRequiresTheRequester,TestFailedRunTellsUser,TestDeliveryRetryNeverRerunsRuntime(internal/host/engine/engine_test.go). - ◆Proposed: a steering message during a tool batch reaches the next model call exactly once, also across a restart (P6).
- ◆Proposed (P29):
TestChatWindow,TestSessionScope,TestResetStartsNewSession,TestHistoryStartMovesInJumps(internal/host/engine);TestMentionsRenderAsNames,TestQuoteFromParentID(plugins/feishu); every attempt of a run receives the sameMessageandChat.