selecting and delegating states, which say which question the loop picked or handed out.
This page explains what a state is, which states exist, how they are stored and how to read them. The run they belong to (its status, the report, the usage) is in research.md, and the agent’s loop in deep-research-agent.md.
What a state holds
Each state is a row ofgb_agent_research_states:
The table is append-only. A state is entered, then ended (
finished_at set); it is never rewritten. The current state of a run is always its last row, and the run’s state field mirrors it.
Each run has its own states. A sub-agent of the investigative loop is a run of its own, so it has its own states, and it is listed with its parent (see subagents.md).
The states
Common to all loops
The usual path of a simple run is
starting, then thinking and a tool state (searching, reading, querying, remembering or using_tool) as many times as the model needs, then thinking again and completed. When the agent uses all its steps, the last model call is writing_report instead, so a run always ends with a report. A run that fails has the state it failed in with the error, followed by a failed state that carries the error too.
Investigative loop
A run of an agent withloop = "investigative" (agent-defs.md) adds these states, which describe the loop’s own steps (deep-research-loop.md):
The
detail of a turn of this loop is turn 7 of 60, question q_003. A tool call inside the loop keeps its usual state (searching, reading, …).
Other
spawning: thespawn_subagenttool of the simple loop was removed in 0.189.0. Runs made before then still have these rows; no new run enters it.importing: only for a run in Modal (runnermodal). The container has ended and the server loads what the agent learned into its databases. Anerroron this state says why the import failed; the run keeps its report.
Reading the states
REST and MCP
GET /v1/gb/research/{id} returns the run with its states, in the order they were entered:
research_get MCP tool. The timestamps and the rest of the states are omitted here. GET /v1/gb/research/{id}/stream pushes the run as Server-Sent Events, and each snapshot carries the states too. The admin UI shows them in the States section of a run’s Details modal.
CLI
gligabao research get ID prints the run with every state it went through. Add --raw to print only the report.
Progress events
The standalone binarygligabao_agent prints one JSON line each time an agent enters a state:
agent is main or the name of a sub-agent, and state_seq numbers the states of that agent from 1. When a state ends with an error, the same state_seq is written once more with the error set.
How the states are recorded
The states are written by the manager of the research (internal/agent_research/). The agent reports each model call and tool run to an observer, and the manager turns them into state rows. The names are constants in internal/agent_research/core/core.go, and the investigative loop’s names are in internal/agent_research/investigate_core/loop_state.go. Both tables are defined in internal/agent_research/db/sqlite/sql/schema.sql and internal/agent_research/db/postgres/sql/schema.sql.
A run of the Modal runner records the states its container reports, and the sub-agents’ states inside it are imported with the sub-agent’s name in front of the detail (research.md).
States and frontier questions, side by side
A question’s
status is a different enum from a run’s state, even where the words look alike.