AgentsRunning agents

Running agents

Run registered Runiq agents through the runtime and HTTP chat endpoint.

Agents are executed by AgentExecutionRuntime, not by calling the Agent instance directly.

The Agent class still contains direct execution methods, but the implementation returns DirectAgentExecutionNotSupported. Use the runtime service from dependency injection.

Run by agent id

C#
using Runiq.Agents.Runtime;

app.MapPost("/ask-weather", async (
    WeatherQuestion request,
    AgentExecutionRuntime runtime,
    CancellationToken cancellationToken) =>
{
    var result = await runtime.ExecuteAsync(
        agentId: "weather-agent",
        input: request.Message,
        cancellationToken);

    return result.IsSuccess
        ? Results.Ok(new { message = result.Message })
        : Results.BadRequest(new
        {
            errorCode = result.ErrorCode,
            errorMessage = result.ErrorMessage
        });
});

public sealed record WeatherQuestion(string Message);

If the runtime cannot find the id, it returns an AgentNotFound failure result.

Stream by agent id

C#
using Runiq.Agents;
using Runiq.Agents.Runtime;

app.MapPost("/ask-weather/events", async (
    WeatherQuestion request,
    AgentExecutionRuntime runtime,
    CancellationToken cancellationToken) =>
{
    await foreach (AgentExecutionEvent executionEvent in runtime.ExecuteStreamAsync(
                       agentId: "weather-agent",
                       input: request.Message,
                       cancellationToken: cancellationToken))
    {
        // Write to your UI transport, logger, or response stream.
        Console.WriteLine($"{executionEvent.Kind}: {executionEvent.Content}");
    }

    return Results.Accepted();
});

Runtime event kinds are:

Event kindMeaning
AssistantDeltaPartial assistant text.
ToolCallStartedThe model requested an attached tool.
ToolCallCompletedA typed .NET tool completed and returned JSON output.
ToolCallFailedA tool call failed.
CompletedAgent execution completed successfully.
FailedAgent execution failed.
ContextProvidedContext Space metadata was attached to the run.
ContextSearchedAttached source documents were searched for the run.
SkillLoadedContext Space skill instructions were loaded.

Run an ad hoc agent

AgentExecutionRuntime also supports executing an Agent instance directly:

C#
var agent = new Agent(
    id: "temporary-agent",
    name: "Temporary Agent",
    instructions: "Answer briefly.",
    model: "openai/gpt-5",
    apiKey: builder.Configuration["OpenAI:ApiKey"]);

var result = await runtime.ExecuteAsync(
    agent,
    "Explain the runtime flow in one paragraph.",
    cancellationToken);

Use registered agents for normal application behavior. Registered agents are easier to inspect through metadata and the dashboard.

Dashboard chat endpoint

UseRuniqDashboard maps the dashboard agent API under the configured dashboard path.

With the default dashboard path /runiq, the chat endpoint is:

HTTP
POST /runiq/api/agents/{agentId}/chat
Content-Type: application/json

{
  "message": "What should I wear in Istanbul today?",
  "responseMode": "Stream"
}

If you configure the dashboard at /dashboard, the endpoint becomes:

HTTP
POST /dashboard/api/agents/{agentId}/chat

responseMode is a JSON string enum:

ValueResponse
StreamServer-sent events with data: ... lines and a final data: [DONE]. This is the default.
ResultOne JSON response containing success state, final message, error details, and execution steps.

Stream event payloads

The dashboard chat stream maps runtime events to lowercase string event types.

Stream typeMain fields
assistant_deltacontent
tool_call_startedtoolCallId, toolName, argumentsJson
tool_call_completedtoolCallId, toolName, outputJson
tool_call_failedtoolCallId, toolName, errorCode, errorMessage
context_providedcontextSpaces, skills, sources
skill_loadedloadedSkills
context_searchedcontextSearchSummary, sourceSearchResults
completedCompletion marker before [DONE].
failedcontent, errorCode, errorMessage

Tool output is not the final answer. It is returned to the model so the model can continue and produce the final assistant response.

On this page