ADR 0003doc/{zh,en}/adr/0003-run-scoped-tool-resources.md
ADR 0003: Run-Scoped Tool Resources
Status: accepted, 2026-11-14. Amended 2026-11-14: localenv no longer stops jobs at the run's end; RunEnded detaches them, and they belong to the conversation's workspace (decision
Status: accepted, 2026-11-14. Amended 2026-11-14: localenv no longer stops jobs at the run's end; RunEnded detaches them, and they belong to the conversation's workspace (decision 2 below; catalog section 5.2).
Context
Three needs of coding work cross the boundary between a tool plugin and the run it serves, and none can be met inside a plugin:
- ◆A person attaches a file (a zip, a log, a screenshot) and no tool can open it: the attachment reaches only the model (P16).
- ◆A background shell job (P28) outlives the call that started it. It should stop when its run ends, and the run should learn when it ended, but a tool plugin is told neither.
- ◆Every approval of a recurring command is asked again:
go test ./...asks once per call for the whole task, which people learn to approve without reading (P27).
Decision
- Opening artifacts (P16).
CallergainsOpenArtifact(ctx, id) (io.ReadCloser, ArtifactRef, error), limited to the calling run's own artifacts: its input attachments and what the run stored withPutArtifact. Another run's id fails withartifact.not_found. The agent names each attachment in<orq:context>with its id, name, type, size and workspace path;localenvcopies an attachment to.orquelo/in/<id>/<name>the first time a file tool or a command names that path. Amended 2026-11-26 (Feishu #169, the owner's choice): a run may also open the files sent with earlier messages of its own session, which history names with their paths; not what other runs produced, and not across sessions (a new session after/newcannot open the old one's). - Run end (P28). A tool plugin may implement
RunEnder { RunEnded(ctx, runID string) }. When a run reaches a terminal state, the Host calls it once on each tool instance that implements it, with a 5 s timeout and best effort;localenvstops the run's jobs. A tool that needs to know how the run ended implementsRunStateEnder { RunEndedState(ctx, runID, state string) }instead or as well (succeeded, failed or cancelled; added 2026-12-03 for computer-use flows, CU13). A tool that a person ran directly (!or a tool directive) may returnToolResult.HandOff: the runtime then goes on with its model in the same run, given that text as the task (a flow's replay that could not place a step). - Reminders from tools (P28).
ToolHostgainsRemind(ctx, kind, text string) error, which queues a reminder for the calling run;RuntimeHostgainsTakeReminders(ctx) ([]Reminder, error), aReminderbeing its source instance, kind and text, which the agent calls before each model call and renders as<orq:reminder source="{instance}" kind="{kind}">. Reminders live with the active run and are lost at a Host restart, like the jobs that send them. - Remembered approvals (P27). An approval answer may have the scope
conversation: the Host stores a grant keyed by (principal, conversation, provider, tool, subject), where the subject is the call's argument atToolSpec.Subject, or the whole tool when the spec names none. A later approval question in that conversation for the same tool and subject is approved by the Host without asking (approval.remembered). Grants respect the current approval setting, end when the tool's pinned digest changes, and never become operator policy. Presentation offers a second approve choice.
Consequences
- ◆
Caller,ToolHostandRuntimeHostgain methods; process plugins reach them through new RPC methods. Plugins that do not use them are unaffected. - ◆A remembered approval lets later identical calls run unasked in one conversation. The subject must match exactly, and the reviewer, guards and rules still apply first.
- ◆The Host keeps reminders in memory only; nothing is replayed after a restart.
Design: Tools sections 6.3 and 10, tool catalog section 5.2, reminders.