> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flowyble.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Execution

> How agents run, process tool calls, and return results.

## Execution flow

When an agent run is triggered (via dashboard, API, or webhook):

<Steps>
  <Step title="Queued">
    A message is sent to the execution queue (Azure Service Bus). The run status is set to **Pending**.
  </Step>

  <Step title="Processing">
    A worker picks up the message, loads the agent configuration, and sets status to **Running**.
  </Step>

  <Step title="LLM Loop">
    The agent enters a loop:

    1. Build the prompt (system message + conversation history + tool definitions)
    2. Call the LLM
    3. If the LLM returns a tool call → execute the tool, add the result to history, repeat
    4. If the LLM returns a final text response → exit the loop
    5. If max steps reached → exit with current output
  </Step>

  <Step title="Quality Check">
    If a QualityChecker system agent is configured, it evaluates the output and assigns a score.
  </Step>

  <Step title="Complete">
    Status is set to **Completed** (or **Failed**). Results are stored and published via SignalR for real-time updates.
  </Step>
</Steps>

## Run metrics

Each run records:

| Metric             | Description                                      |
| ------------------ | ------------------------------------------------ |
| **Steps Executed** | Number of tool-call iterations                   |
| **Tokens Used**    | Total input + output tokens across all LLM calls |
| **Actions Used**   | Number of tool/function executions               |
| **Credits Used**   | Total credit cost based on model pricing         |
| **Duration**       | Wall-clock time from start to finish             |

## Step details

Each step within a run records:

* **Tool Name** — which function was called
* **Input Data** — parameters passed to the tool
* **Output Data** — result returned by the tool
* **Reasoning** — the LLM's chain-of-thought before the tool call
* **Token Usage** — per-step input/output tokens
* **Duration** — execution time in milliseconds

## Hierarchical runs

Agents can invoke other agents using the **InvokeAgent** tool. This creates a parent-child relationship:

* The parent run's `ParentAgentRunId` links child runs
* Child runs execute independently with their own step limits and credit tracking
* The parent agent receives the child's final output as a tool result

## Error handling

When an agent run fails:

* The **ErrorAnalyzer** system agent (if enabled) examines the error and provides diagnosis
* The error message is stored on the run record
* Credits consumed up to the point of failure are still deducted

Common failure reasons:

* LLM API timeout or rate limit
* Tool execution error
* Max steps exceeded without resolution
* Insufficient credits
