Skip to main content

Protocol Reference

This document provides a complete reference for the ACP (Agent Client Protocol) methods and streaming events exposed by the iac-code server.

Lifecycle Overview

A typical ACP session follows this flow:

initialize → new_session → prompt (loop) → close_session
↑ │
└── load_session / resume ──────┘
  1. initialize — Handshake. Negotiate protocol version and discover server capabilities.
  2. session/new — Create a fresh session with an independent agent runtime.
  3. session/prompt — Send user input; receive streaming events until a final response.
  4. session/close — Release the session and its resources.

Sessions can also be loaded from history (session/load) or resumed (session/resume) instead of creating new ones.


Methods

initialize

Protocol handshake. Must be the first call on every connection.

Request Parameters

FieldTypeRequiredDescription
protocolVersionintegerYesRequested protocol version (currently 1)
clientInfoobjectNoClient name and version
clientCapabilitiesobjectNoCapabilities the client supports

Response Fields

FieldTypeDescription
protocolVersionintegerNegotiated protocol version
agentCapabilitiesobjectServer capabilities (see below)
agentInfoobjectServer name and version
authMethodsarrayAvailable authentication methods (empty if using built-in credentials)

Agent Capabilities

CapabilityValueMeaning
loadSessiontrueSupports restoring sessions from history
promptCapabilities.embeddedContexttrueAccepts embedded resource content in prompts
promptCapabilities.imagefalseImage input not supported (degrades to text marker)
promptCapabilities.audiofalseAudio input not supported (degrades to text marker)
sessionCapabilities.list{}Supports listing sessions
sessionCapabilities.close{}Supports closing sessions

session/new

Create a new session with an independent agent runtime, tool registry, and LLM context.

Request Parameters

FieldTypeRequiredDescription
cwdstringYesAbsolute path to the working directory
mcpServersobjectNoMCP server configuration (accepted but not yet functional)

Response Fields

FieldTypeDescription
sessionIdstringUnique session identifier for subsequent calls
modesobjectAvailable modes and current mode
modelsobjectAvailable models and current model
note

Each session creates an independent AgentLoop. Multiple sessions can run concurrently but each consumes an LLM connection.


session/load

Load a previously persisted session from disk, restoring its message history.

Request Parameters

FieldTypeRequiredDescription
cwdstringYesWorking directory path
sessionIdstringYesID of the session to load

Response Fields

FieldTypeDescription
modelsobjectAvailable models and current model state
modesobjectAvailable modes and current mode state
note

Loading a session reads history from ~/.iac-code/sessions/, auto-repairs interrupted messages, and injects history into a fresh AgentLoop.


session/fork

Fork an existing session to create an independent branch with the same history.

Request Parameters

FieldTypeRequiredDescription
cwdstringYesWorking directory path
sessionIdstringYesID of the session to fork

Response Fields

FieldTypeDescription
sessionIdstringNew session ID for the forked branch
modelsobjectAvailable models and current model state
modesobjectAvailable modes and current mode state

session/resume

Resume or reconnect to an existing session. Automatically loads history if needed.

Request Parameters

FieldTypeRequiredDescription
cwdstringYesWorking directory path
sessionIdstringYesID of the session to resume

Response Fields

FieldTypeDescription
modelsobjectAvailable models and current model state (optional)
modesobjectAvailable modes and current mode state (optional)
note

Unlike session/new, the response does not include a sessionId field since the client already knows the session ID from the request.


session/prompt

Send user input and trigger streaming agent responses.

Request Parameters

FieldTypeRequiredDescription
sessionIdstringYesTarget session ID
promptarrayYesArray of content blocks (see Content Block Types below)

Content Block Types

TypeDescription
TextContentBlockPlain text user input
EmbeddedResourceContentBlockFile content embedded inline
ResourceContentBlockResource link reference
ImageContentBlockImage (degrades to [image: mime/type] text marker)
AudioContentBlockAudio (degrades to [audio: mime/type] text marker)

Response Fields

FieldTypeDescription
stopReasonstringWhy the prompt completed (see Stop Reasons)
usageobjectToken usage: inputTokens, outputTokens, totalTokens

Stop Reasons

ValueMeaning
end_turnModel completed normally
max_turn_requestsHit maximum tool-call loop limit
max_tokensOutput token limit reached
cancelledClient cancelled the prompt
refusalModel refused to answer
note

During execution, the server pushes session/update notifications with streaming events before returning the final response.


session/cancel

Cancel a running prompt task.

Request Parameters

FieldTypeRequiredDescription
sessionIdstringYesSession with the running prompt

Behavior

  • Stops consuming stream events
  • Running tools are not forcefully terminated, but results are discarded
  • The pending prompt call returns with stopReason: "cancelled"

session/close

Close a session and release its resources.

Request Parameters

FieldTypeRequiredDescription
sessionIdstringYesSession to close

Behavior

  • Session removed from memory
  • Persisted history remains on disk
  • Subsequent prompt calls to this session return an error

sessions/list

List all persisted sessions for a given working directory.

Request Parameters

FieldTypeRequiredDescription
cwdstringYesWorking directory to scope the listing

Response Fields

FieldTypeDescription
sessionsarrayList of session objects with sessionId and metadata

config/set

Dynamically set a configuration option for a session.

Request Parameters

FieldTypeRequiredDescription
sessionIdstringYesTarget session
configIdstringYesConfiguration key to set
valueanyYesNew value

Streaming Events

During session/prompt execution, the server pushes session/update notifications containing streaming event data.

Event Format

Each session/update notification carries an update object with a specific type:

{
"jsonrpc": "2.0",
"method": "session/update",
"params": {
"sessionId": "abc123",
"update": { "type": "agent_message_chunk", "text": "..." }
}
}

Event Type Mapping

Internal EventACP Update TypeDescription
TextDeltaEventAgentMessageChunkIncremental agent text output
ThinkingDeltaEventAgentThoughtChunkModel reasoning/thinking content
ToolUseStartEventToolCallStartTool invocation begins
ToolResultEventToolCallProgressTool result (completed or failed)
CompactionEventAgentMessageChunkContext compaction notification
ErrorEventAgentMessageChunkError information

Tool Call Lifecycle

ToolCallStart (status=in_progress)

├── ToolCallProgress (status=in_progress, raw_input=tool input)

├── ToolCallProgress (status=completed, raw_output=result) ← success

└── ToolCallProgress (status=failed, raw_output=error) ← failure

Tool Kind Mapping

ToolACP ToolKind
read_file, list_filesread
glob, grepsearch
write_file, edit_fileedit
bash, agentexecute
web_fetchfetch
Othersother

Permission Requests

Before executing high-risk tools, iac-code sends a request_permission callback to the client.

Tool Permission Categories

CategoryToolsAuto-allowed
Read-onlyread_file, list_files, glob, grep, web_fetchYes
Writewrite_file, edit_fileNo — requires approval
Executebash, agentNo — requires approval

request_permission Event

The server sends a request_permission callback with:

FieldTypeDescription
optionsarrayAvailable permission choices
sessionIdstringSession requesting permission
toolCallobjectTool call details (title, kind, input)

Permission Options

Option IDMeaning
allow_onceAllow this specific invocation
allow_alwaysAllow all future calls of this tool in this session
reject_onceDeny this specific invocation
reject_alwaysDeny all future calls of this tool in this session

Response Format

{
"outcome": "allowed",
"option_id": "allow_once"
}

Or to deny:

{
"outcome": "denied"
}
Client ResponseTool Behavior
AllowedOutcomeTool executes normally
DeniedOutcomeTool skipped; model receives "Permission denied." error

Error Handling

RequestError Format

Errors follow JSON-RPC 2.0 error format:

{
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": -32602,
"message": "Invalid params",
"data": {"session_id": "Session not found"}
}
}

Common Error Codes

CodeNameDescription
-32700Parse errorInvalid JSON
-32600Invalid requestMalformed JSON-RPC
-32601Method not foundUnknown method
-32602Invalid paramsMissing or invalid parameters (e.g., unknown session ID)
-32603Internal errorServer-side failure