Agent runner system
Summary
Runtime agents that use LLM providers, local deterministic functions, and other agents to perform tasks. Sidebar chat sessions are now workflow-backed: each chat is one long-lived workflow run, and the runner API projects current session state from workflow events while preserving existing panel behavior.
Motivation
LLM-based agents needed a runtime layer beyond the raw OpenAI conversation client. This system provides:
- Agent runner with workflow-backed session lifecycle, tool execution, and approval flow
- Preset system exposing context-aware capabilities (MCP tools) with risk badges
- Streaming replies from OpenCode and other providers
- Agent scope within reloadable units
Design
- Workflow-backed runner facade: Preserves the sidebar runner API (
create-session,get-session,list-sessions,run-turn,cancel-turn,delete-session,flush,drop) while storing current chats as workflow runs. - WorkflowStore: Owns agent chat workflow definitions, long-lived runs, run steps, and event history.
- Event projection: Projects transcript, status, and session data from workflow events such as
:agent-session-created,:agent-status-changed, and agent item events. Old JSON session files are not the current chat source of truth. - PresetRegistry: Defines available capabilities as presets with three-state control (Auto/On/Off) and risk badges
- MCP transport: Remote OpenCode MCP transport for tool exposure across processes
- Conversation-first supervisor: Streaming with tee for parallel consumers
- Approval: Toggle-driven — preset toggle is user action; tool execution remains model action with approval checks
Workflow-backed session flow
- The sidebar calls
create-session, which ensures the editable default agent workflow exists and starts a long-lived workflow run. - The workflow waits for
:agent-user-input. - Each
run-turnappends the user message as a workflow event, resumes the waiting step, and lets the provider-specific turn controller stream items/status back as more workflow events. - The sidebar and graph read the same projected workflow run/session state.
- Legacy
agent-sessions/*.jsonfiles are migrated only by the explicittools.agent-session-migratecommand, not during app startup.
Tasks
- [x] Agent runner with session lifecycle
- [x] Preset system with MCP tool exposure
- [x] Risk-based approval model
- [x] OpenCode streaming integration
- [x] Remote MCP transport
- [x] Conversation-first supervisor
- [x] Workflow-backed sidebar sessions and explicit legacy migration
