Running agents
Execute a registered agent and handle results, streaming events, and failures.
Resolve AgentExecutionRuntime through dependency injection. Use it to run the support-agent registered in Defining agents.
The same runtime APIs execute Codex CLI and Claude CLI agents. Use their registered id in place of support-agent. Keep the invoking DI scope alive until execution or stream disposal completes.
Return one completed response
Add this endpoint before app.Run(). Put the record declaration after the top-level statements.
Send a JSON body such as { "message": "How can I describe a problem clearly?" } to POST /ask. This example returns the runtime result; choose HTTP status codes and error disclosure appropriate to your application.
Consume streaming events
The runtime also produces an asynchronous event stream. In a handler or service with an injected runtime, consume it as follows:
This example logs events. To stream to a browser, connect the events to your transport or use the Studio chat endpoint described below.
Handle failures and cancellation
An unknown registered id returns AgentNotFound. Model execution with missing required credentials can return ApiKeyMissing. CLI executors report installation and authentication errors such as CodexNotInstalled, ClaudeNotInstalled, CodexAuthenticationFailed, or ClaudeAuthenticationFailed. Inspect the completed result's success state or a stream's failure event; CLI failure does not fall back to a model provider.
Pass the caller's cancellation token through to execution. Let your endpoint or service handle cancellation consistently with the rest of the application.
Call the runtime rather than Agent.ExecuteAsync; direct execution on the definition returns DirectAgentExecutionNotSupported.
Execute an unregistered definition
For an ad hoc run, pass an existing Agent definition:
Use registered definitions for normal application behavior when callers and Studio need to discover them by id.
For an unregistered CLI definition, its matching executor must already be registered in the host. AddRuniqServer automatically registers CLI infrastructure only for the CLI kinds selected by the agents in its registration callback. A runtime missing the matching executor returns AgentExecutorNotSupported.
Continue a CLI conversation
Every invocation receives a fresh RunId. To continue CLI history, use the confirmed ProviderSessionId from a previous successful result:
The same pattern works with claude-analyst. A RunId is not a provider session key. The host must authorize session ownership and bind it to the correct agent and workspace. Concurrent execution of the same session within one host is rejected. Calls without ProviderSessionId start a fresh CLI conversation.
Continuation is available through AgentQuery; Studio chat does not expose a continuation control or HTTP request session field. Interactive approval waiting and resumption are unsupported.
Runtime event reference
| Kind | Meaning |
|---|---|
AssistantDelta | Partial assistant text. |
ToolCallStarted | The model requested an attached tool. |
ToolCallCompleted | A tool returned its output. |
ToolCallFailed | A tool call failed. |
RagSearch | Structured retrieval lifecycle information in RagSearch. |
Completed | Successful completion, with RAG metadata and citations when available. |
Failed | Execution failure and error details. |
Tool output is returned to the model for continuation; it is not necessarily the final answer.
Studio HTTP endpoint
With Studio hosted at /dashboard, its agent endpoint is:
The default dashboard path is /runiq; the endpoint follows the configured path. Studio authentication applies. See Studio hosting.
| Response mode | Output |
|---|---|
Stream | Server-sent events, ending with data: [DONE]. Default mode. |
Result | One JSON response with the completed result. |
Stream event types
| Type | Main payload |
|---|---|
assistant_delta | content |
tool_call_started | toolCallId, toolName, argumentsJson |
tool_call_completed | toolCallId, toolName, outputJson |
tool_call_failed | Tool identity and error details |
rag_search_started | ragSearch: index, query, and retrieval configuration |
rag_search_completed | ragSearch: selected/rejected results and search diagnostics |
rag_search_blocked | ragSearch: blocked retrieval details |
rag_search_failed | ragSearch: failure classification |
completed | RAG metadata and citations when available |
failed | Error details and RAG metadata when available |