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.
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. Missing required credentials can return ApiKeyMissing. Inspect the completed result's success state or a stream's failure event.
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.
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 |