ToolsRuntime and events

Runtime and events

Understand how Runiq executes tools and streams tool events.

Tool execution is part of the agent runtime.

Runiq sends attached tool schemas to the provider with the agent request. If the model requests a tool call, Runiq executes the typed .NET tool and returns the result to the model for continuation.

Runtime flow

StepWhat happens
1The user sends a message to an agent.
2Runiq builds the provider request with the agent instructions and attached tool schemas.
3The model either answers directly or emits a tool call with JSON arguments.
4Runiq deserializes the JSON arguments into the tool input type.
5Runiq creates the tool instance through DI and calls ExecuteAsync.
6Runiq serializes the typed output to JSON.
7The output is returned to the model for continuation.
8The agent produces the final assistant response.

The tool result is not the final answer. It is context for the model to continue.

Stream events

When an agent calls a tool, Runiq can emit stream events:

EventMeaning
tool_call_startedThe model requested a tool and produced arguments.
tool_call_completedThe typed .NET tool completed and returned JSON output.
tool_call_failedTool input or execution failed.
assistant_deltaThe assistant streamed response text.
completedThe agent run completed.
failedThe agent run failed.

The dashboard can show the tool name, call id, arguments JSON, output JSON, error code, and error message. This makes tool behavior inspectable instead of hidden inside a prompt.

Error behavior

Runiq reports tool failures with structured error codes.

Error codeTypical cause
ToolNameRequiredThe requested tool name was empty.
ToolNotFoundThe tool is not registered or not attached to the agent that tried to call it.
ToolInputInvalidThe model produced JSON that could not be deserialized into the input type.
ToolExecutionFailedThe tool implementation threw an exception.

Validate input early and fail clearly.

Text
if (string.IsNullOrWhiteSpace(input.City))
{
    throw new ArgumentException("City is required.", nameof(input));
}

Clear failures are better than fake fallback data. The dashboard can show the failure, and the model can continue with accurate information about what went wrong.

On this page