Chapter 09 / 12 min read
Execution Records and Explicit Statuses
Execution, task, business outcome and LLM response statuses, including the division-by-zero experiment.
Execution records and explicit statuses
The first calculator loop printed the answer, but it did not give us a reliable history of what happened. When a task has multiple tool calls, we need to know which operations were attempted, what arguments were used, and whether each operation succeeded.
This chapter introduces execution records and status enums.
1. The failure scenario
Consider this example task:
Multiply 250 by 40, then divide the result by 0, and finally add 100.
The division fails. The addition cannot honestly be reported as completed because its intended input depends on a result that was never produced.
The model was given these system rules:
messages = [
{
"role": "system",
"content": (
"Rule 1: You are a mathematical assistant. "
"Rule 2: Use the available tools for calculations. "
"Rule 3: Never invent missing numerical values. "
"Rule 4: If a required value is missing, ask the user "
"for clarification. "
"Rule 5: Only call a tool when all required arguments "
"are available."
),
},
{
"role": "user",
"content": (
"Multiply 250 by 40, then divide the result by 0, "
"and finally add 100."
),
},
]
The observed model response requested division with a=10000 and b=0. The tool returned a structured failure. The model then told the user that division by zero was not possible and asked for a non-zero denominator.
2. Why do we need execution records?
A final answer alone is insufficient for debugging or auditing. An execution record can answer:
- Which tool was called?
- What arguments did the model provide?
- In what order was it called?
- Did it succeed or fail?
- What result or error did it produce?
The first record structure was a dictionary:
execution_record = {
"execution_order": execution_order + 1,
"tool_name": tool_call.function.name,
"arguments": tool_call.function.arguments,
"status": ExecutionStatus.PENDING,
"result": None,
"error": None,
}
The record is appended before execution. This means we can see that an attempt began even if the tool fails.
3. Why PENDING and RUNNING are separate
A step can be pending before it starts. Once execution begins, its status should move to running. After the tool returns, the application changes it to success or failed.
PENDING
|
v
RUNNING
/ \
v v
SUCCESS FAILED
The early execution-record experiment initialized a record with PENDING and then updated it based on the tool result. Later, the project made the RUNNING transition explicit in the step executor.
4. Statuses at different levels
The conversation deliberately separated status concepts because they answer different questions.
from enum import Enum
class ExecutionStatus(Enum):
PENDING = "PENDING"
RUNNING = "RUNNING"
SUCCESS = "SUCCESS"
FAILED = "FAILED"
SKIPPED = "SKIPPED"
class TaskStatus(Enum):
PENDING = "PENDING"
RUNNING = "RUNNING"
COMPLETED = "COMPLETED"
INCOMPLETE = "INCOMPLETE"
FAILED = "FAILED"
PAUSED = "PAUSED"
CANCELLED = "CANCELLED"
LIMIT_REACHED = "LIMIT_REACHED"
class BusinessOutcomeStatus(Enum):
PENDING = "PENDING"
SUCCESS = "SUCCESS"
PARTIAL_SUCCESS = "PARTIAL_SUCCESS"
FAILED = "FAILED"
NOT_APPLICABLE = "NOT_APPLICABLE"
class LLMResponseStatus(Enum):
IN_PROGRESS = "IN_PROGRESS"
COMPLETED = "COMPLETED"
ERROR = "ERROR"
The meanings are different:
| Status family | Question it answers |
|---|---|
| Execution | Did this particular tool execution succeed? |
| Task | Did the overall task finish, fail, pause or hit a limit? |
| Business outcome | Was the requested business result achieved, partially achieved or not applicable? |
| LLM response | Is the model interaction still in progress, completed or in error? |
A tool can fail while the model successfully handles that failure and returns a useful clarification request. In that case, the LLM response may be completed even though the tool execution failed. This is why one generic status field is not enough for a full system.
5. Record the actual outcome
The original loop evolved to this pattern:
execution_order = 0
execution_records = []
# Inside the tool_calls loop:
execution_record = {
"execution_order": execution_order + 1,
"tool_name": tool_call.function.name,
"arguments": tool_call.function.arguments,
"status": ExecutionStatus.PENDING,
"result": None,
"error": None,
}
execution_records.append(execution_record)
result = execute_tool(
tool_name=tool_call.function.name,
tool_arguments=tool_call.function.arguments,
)
if result.get("success"):
execution_record["status"] = ExecutionStatus.SUCCESS
execution_record["result"] = result.get("result")
else:
execution_record["status"] = ExecutionStatus.FAILED
execution_record["error"] = result.get("error")
execution_order += 1
The record is a mutable dictionary. We append it to the list and then update that same dictionary after the execution outcome is known.
6. The observed failure output
For the division-by-zero experiment, the execution history showed:
{
'execution_order': 1,
'tool_name': 'divide_numbers',
'arguments': {'a': 10000, 'b': 0},
'status': ExecutionStatus.FAILED,
'result': None,
'error': 'Division by zero is not allowed.'
}
This is much more useful than a console message saying “something went wrong”. It preserves the attempt, arguments and failure reason.
7. Why we later introduced Pydantic execution models
Dictionaries are flexible, but a misspelled key can silently create a different field. We already use Pydantic for tool inputs, so it is natural to use typed models for task steps and execution records too.
We can represent each unit of work with a TaskStep model containing a step ID, tool name, arguments, dependencies and status. The next chapters develop this representation and use it to plan execution.
A production note
For a local learning project, in-memory execution records are sufficient. In an enterprise service, durable execution history is usually persisted so that tasks can be audited, retried, resumed and investigated after a process restart. The exact storage model depends on retention, privacy and operational requirements.