fetch_url), checks claims against more than one source, and ends with a report. It also works with the user’s internal knowledge base: it remembers the important snippets it finds as it goes and querys the knowledge base besides the web (see below). gligabao runs it as a job: you start it, it returns at once with a run, and you follow what it does until it ends.
Every run is stored in the relational database, and so is every state the agent goes through while it works (searching a query, reading a page, waiting for the model, …), so its progress can be followed in detail, and kept afterwards.
It needs an Anthropic API key (else 503). Each run costs money: up to max_steps model calls plus the web searches (a fee for each, on top of the tokens, see web-search.md). The cost is recorded and updated as the run goes.
By default the agent runs in the server’s process (the local runner). With "runner": "modal" it runs instead as the gligabao_agent binary in Modal, started through the sidecar the way training is (below).
Access: REST (below), MCP (research_start, research_list, research_get) and the CLI (gligabao research start|ls|get). They all use the same handlers, so they behave the same.
Runs and states
A run (gb_agent_research_runs) is one execution of the agent on a topic. Its status is its lifecycle:
The report and its summary
The report of a run is not a column of the run: it is a row ofgb_agent_research_reports (run_id, report, summary, created_at; at most one per run), written in the same transaction that ends the run. GET /v1/gb/research/{id}, the list, the stream, the CLI and the admin UI show both as report and summary of the run. A worker’s row holds its findings (JSON) and has no summary; a failed or stopped run has no row.
The summary is shorter and at a higher level than the report (one to three paragraphs, at most about 150 words: the question, the main conclusions, how reliable they are). It is made at the end of a research that completed, by one separate model call (internal/agent_research/summary.go): no tools and none of the agent’s context, only the topic and the finished report, on the model of the run. It is not part of the agent’s reasoning, and it is not a step of the run; what it costs (tokens and USD) is added to the totals of the run, and it applies to runs of the modal runner too (the server makes it). If the call fails the run still completes, with the report and an empty summary (a warning is logged).
Migration (0.207.0). Before it the report was the column gb_agent_research_runs.report. When the manager starts it checks whether that column still exists; if it does, in the background it copies every report into gb_agent_research_reports (with the summary of each research, made by the same call; the findings of workers get none) and then drops the column, so the migration never runs again. Without an LLM client it waits for the next start; a failed summary stops it without dropping the column, and the next start goes on. Reports that were not migrated yet are not shown until then. The code is all in internal/agent_research/migrate_reports.go, marked as a one-off to remove.
A run left running by a process that died is marked failed (“interrupted”) when the server starts again (the job of a run in Modal is not followed again after a restart: see the runner).
A state (gb_agent_research_states) is one stage of its work (the full guide is states.md). A row is inserted every time the agent moves from one state to the next; the table is append-only (a state is only ended, never rewritten), and state of the run is always the last row’s. The states of a run:
The agent goes
starting, then thinking, searching/reading/querying/remembering and thinking again, as many times as it needs, and ends: thinking, completed when the model answers before the last step; or writing_report, completed when it uses all its steps (the last step cannot call tools, so a run always ends with a report). A model that does not use tools in the first step goes starting, thinking, completed.
Columns of a state: seq (1, 2, 3, … in the order entered), step (the model call it was on; 0 for starting, completed and failed), detail, error, started_at and finished_at (null for the state the run is in; millisecond precision). A tool that fails (a page that cannot be read) does not fail the run: the model is told and goes on, so the state has an error and the run can still complete. When a run fails, the state it failed in and the failed state both carry the error.
The run keeps steps (model calls made; for an investigative run the turns), tool_calls, input_tokens, output_tokens and cost_usd, updated after every model call and tool run. The cost includes the model calls of the web searches.
REST
All three routes are user routes: the user is thegb-user-id header (required; never read from the body or the query string), and with the Auth hook the API key sets it. A user only sees their own runs: another user’s run is a 404.
POST /v1/gb/research
Starts an agent. Body:
topic(required, at most 2000 characters): what to research. A question, or a subject to write a report on.agent(optional, defaultdefault): the agent definition to run (GET /v1/gb/research/agentslists them); an unknown one is a400.agent_version(optional) is a constraint its version must meet (1.2.0,>=1.0,^1.2); a mismatch is a400. The run recordsagent_name,agent_versionandagent_hash.max_cost_usd(optional, 0 = none): a cap in USD on what the whole research may spend, sub-agents included. It can lower the caps of the definition and of the server (research_max_cost_usd), never raise them. When it is reached the agents write their reports and the report says so (cost caps).max_steps(optional, default: themax_stepsof the definition: 20 fordefault, 60 forinvestigator): the most model calls (steps) the agent makes, the last of which writes the report. More steps let it search and read more, and cost more. The range depends on the agent’s loop: 1 to 40 for the simple loop, 2 to 300 for the investigative one (a400outside it, naming the range).GET /v1/gb/research/agentslists the range of each agent (steps_min,steps_max).model(optional): the model it runs on, which must support Anthropic’s web search tool. Default: themodelof the definition, else the server’s default model. It is the model of the main agent; its workers run on the same model.dataset(optional, defaultmain): the dataset of the user’s knowledge base the agent queries and remembers into (below). It is created by the firstrememberif it does not exist; a bad name is a400. It is not stored with the run. With themodalrunner it is the dataset the agent’s knowledge lands in when the agent ends (below).no_remember(optional, defaultfalse): with the investigative loop, when the root agent has written the final report, the run makes one explicit, waitingremembercall with it (titled with the topic) intodataset, through the remember pipeline, so that knowledge builds up (the run is in the staterememberingmeanwhile).trueturns that call off. A failed call is logged and does not fail the research. The agent’sremembertool is not affected, and the call is skipped for agents without a knowledge base. Themodalrunner does not use the investigative loop.investigate(optional): the knobs of the investigative loop (max_total_tokens,min_sources, … the same names as the[investigate]table of the agent definition), over those of the definition. Only for an agent withloop = "investigative": with the simple loop they are a400. With the investigative looprunner: "modal"is a400too.search_providerandfetch_provider(optional): the service that runs the agents’web_searchtool and the one that reads the pages offetch_url(the sub-agents use the same). The built-in defaults areanthropicfor search (Anthropic’s cloud web search) andlocalfor fetch (a plain HTTP GET from the server);research_search_providerandresearch_fetch_provideringligabao.tomlchange those defaults, and a request overrides them. The two are chosen independently.linkupandkeenableare available for search and fetch (linkupneedslinkup_api_key/LINKUP_API_KEY, a start without it is refused;keenableis keyless by default). A name that is not available for the operation (localfor search,anthropicfor fetch) is a400, like any other unknown name. Themodalrunner supports onlyanthropicandlocal(a400otherwise). The providers are not stored with the run. Details: Web search and fetch providers. CLI:--search-provider,--fetch-provider(also ofgligabao_agent); MCP: the same names as here.runner(optional, defaultlocal): where the agent runs,local(in the server, as always) ormodal(thegligabao_agentbinary in a Modal container, see below). Any other value is a400. The run says which one it has (runner).
202 with the run (status running, state starting); the agent goes on in the background. 400 for a bad body, 409 if the user already has 3 agents working (wait for one to end), 503 without an Anthropic API key (for local), or, for modal, when the sidecar cannot start the job (it is down, or the Modal app has no agent: the message says which).
GET /v1/gb/research/agents
{"agents": [...]}: the agent definitions a research can run, by name, each with name, version, description, hash, source (the file, or builtin), loop (simple or investigative), model, max_steps (its default), steps_min and steps_max (the range max_steps may have for its loop), max_cost_usd, max_tree_cost_usd, knowledge, skills and max_parallel (the workers its investigative loop runs at once; 1: none).
GET /v1/gb/research
Lists the agents of the user, newest first, without their states: {"runs": [...]}.
active=true: only the agents that are working now (statusrunning).status=running|completed|failed|stopped: only the runs with that status (not together withactive).parent_id=<run id>: only the sub-agents (workers) that run started.limit: at most this many (default 50, at most 500).
parent_id, name and reason set (null/"" for a research a user started).
GET /v1/gb/research/{id}
Reads one run with its states, in the order they were entered. The report and its summary are in it once status is completed.
research_get, or gligabao research get), or stream it (below).
POST /v1/gb/research/{id}/stop
Stops a research of the user that is working (and its sub-agents): the run ends as stopped, with error saying the user, and no report. It answers 200 with the run as it is then. 404 for an unknown id or another user’s research (the admin route POST /v1/gb/admin/api/research/{id}/stop is the one that stops any user’s), 409 if it has ended already, 400 for a bad id.
GET /v1/gb/research/{id}/stream
Server-Sent Events that follow a research until it ends; for a finished one they replay it (one snapshot, then done). The route is the same for the research of any user’s own id; the research of another user is a plain 404 (before the stream starts).
snapshot: everything a UI shows about the research, as of one moment:{"run": {...}, "subagents": [...], "investigation": {...}}.runis the run asGET /v1/gb/research/{id}returns it (with itsstatesand, once completed, itsreport),subagentsthe workers of the investigative loop in the order they were started (runs, without states),investigationwhat the investigative loop built (phase,stop_reason, thequestionsof the frontier, thechallengesand the latestnotes, as in the admin UI) andnullfor a run of the simple loop. The first one is sent at once, then one each time something changed (the server reads the run once a second).done:{"status": "completed"|"failed"|"stopped"}, after the last snapshot, when the run is not active any more. The stream ends.error:{"error": "..."}if the run cannot be read any more. The stream ends.
: ping) is written every 10 seconds of silence to keep proxies from closing the stream. Implementation: internal/api/research/stream.go.
CLI
--runner modal runs the agent in Modal (below); the default is local. start prints the run right away; with --wait it waits for the agent to end and prints the finished run (exit code 1 if it failed), and --raw prints only the report. get --raw prints only the report. See cli.md.
Admin UI
The research view of the admin UI shows the agents of the standard database, any user’s:- the number of agents working now, and of the ones that completed, failed or were stopped;
- active agents, each with a Stop button (it asks to confirm);
- stopped and finished agents (all, or only the completed, failed or stopped ones);
- for every agent, in its row: the number of children (sub-agents it started), its running time (from its start to its end, or to now while it works) and how long ago it started (minutes, hours, days or months);
- a Details modal per agent: the model it ran on (the one recorded for the run: a run started without a model records the server’s default model), whether it started sub-agents (each with its reason and status, to open or stop), its parent, its report (rendered as Markdown, sanitized as HTML) and its states;
- for an agent that failed, a red failed button in its row that opens the error it failed with and the state it failed in;
- a definitions button that opens a modal with every loaded agent definition: one card each, with badges (version, loop, schedule), the settings (model, tools, limits, search, knowledge, investigate, code, schedule) in titled panels, tools as pills, and the system prompt and skills rendered as Markdown (
GET /v1/gb/admin/api/research/agent-defs,{"definitions": [...]}); - a Knowledge button per agent: its provenance, see below;
- a Temporal plot button in the Details modal (next to Knowledge): what the agent did to the facts over time, see below;
- for an investigative run (
phaseset), the Details modal also shows its loop, phase and stop reason, and an Investigation block: the frontier as a tree of questions (status, priority, attempts, answer), the challenges (target, strategy, negation tried, outcome, evidence) and the latest notes. It refreshes with the modal while the run works (GET /admin/api/research/{id}/investigation). Claims, sources and the history of the questions are not shown yet; - a green start agent button that starts an agent, see below (a dropdown next to it picks the kind of agent, investigative by default, which runs the built-in
investigatoragent, or simple, which runsdefault; an investigative agent runs locally only, so the Modal runner is turned off for it); - a dock of the agents that work, see below.
admin, with the defaults of POST /v1/gb/research (20 steps, the server’s model, the main dataset), and the modal closes when the server accepts it. The Details modal of an agent says where it runs.
The dock. A block on the right of the screen, fixed so it stays while the page scrolls, for every agent that works: its state, topic, running time and steps. It is green while the agent is healthy (working or completed) and red when it failed, was stopped, or the server cannot be reached. An agent that ends while its block is shown keeps the block, with its final status, until it is dismissed. Clicking a block opens the details of the agent. The Details modal of a working agent redraws itself every few seconds and keeps its States section open and its scroll position.
Stopping. Manager.Stop cancels the context of the agent, so its model call or tool is interrupted; its run ends as stopped (error stopped by the admin UI, no report) and so do its sub-agents (error stopped: the agent that spawned it (run N) was stopped by ...). Stopping a sub-agent leaves its parent working: its question goes back to the frontier with the failure logged (subagents.md). An agent that has ended cannot be stopped (409). Text the agent queued with remember is not tied to the run, so it is still absorbed. There is no user route for it yet, only the admin one.
Provenance. Everything the remember tool stores carries the session research-<run id> (agent_research.SessionID), and the graph records it on the artifacts (gb_artifacts.session_id), on every entity that session discovered (gb_entity_sessions) and on every fact (gb_edge_sessions), also when the entity or fact was stored before and the agent only found it again. The provenance of an agent is what those tables hold for its session, in any dataset (the run does not store its dataset): the artifacts (texts, chunks, web search results), the entities and the facts, each with the datasets they are in, and, for facts, whether an artifact of the agent created it (created) or the agent restated it. With include_subagents the sessions of its sub-agents are included and each item says which agent it comes from. The modal can open the graph of a dataset, or draw a graph of only what the agent contributed.
Temporal plot. The Temporal plot button of the details modal opens the same plot as the Temporal changes of a remember run: what the agent did to the facts over event time (created, confirmed, ended, invalidated, superseded). It covers the whole session research-<run id> in whichever dataset the agent remembered (the artifacts and events of each event are read from the dataset of that event, so a plot can span several datasets), and the sub-agents’ sessions too when the agent has any. The queries the agent asked (query) carry the same session in the query run log (gb_query_runs).
Endpoints (admin routes, under /v1/gb/admin/api/, not tied to a user): GET research[?status=running|completed|failed|stopped|finished][&user_id=][&roots_only=true][&limit=] (the counts of all the agents by status and the agents that match, each with children, duration_ms, age_ms and has_report, without their reports), GET research/{id} (the agent with its report, states, parent and sub-agents), POST research (starts an agent like POST /v1/gb/research, with the body {"topic": "", "user_id": "admin", "max_steps": 20, "model": "", "dataset": "", "runner": "local"}, only topic required; answers 202 with the agent, and 400, 409 and 503 as there), POST research/{id}/stop, GET research/{id}/provenance[?include_subagents=true] (datasets, artifacts, entities and edges) and GET research/{id}/temporal[?include_subagents=true] (artifacts and events, as in GET remember-run-temporal). They are mounted with the admin UI (internal/api/admin/research.go), and only read or stop the agents of the server’s own database.
Where the agent runs (the runner)
A research has a runner, chosen when it is started (runner in the REST body, --runner in the CLI, runner in research_start, the choice in the admin UI):
The server never talks to Modal: for
modal it asks the sidecar (POST /research/job_start), which spawns a function of the same Modal app that trains (modal.md), whose container runs the binary (deep-research-agent.md) on the topic, with the sub-agents inside it. The server records the run exactly as for a local one (gb_agent_research_runs, with runner modal), follows the job’s event stream (SSE, like a training job’s) and writes what the container reports to the run: the states the agents enter, the usage and, in the end, the report. REST, MCP, the CLI and the admin UI see the same run and the same states; only runner differs.
- The agents run inside the container (the simple loop: there are no sub-agents since 0.189.0; the investigative loop is not supported by this runner). The states that sub-agents entered in a run made before are in the timeline with the name of the sub-agent in front of the detail (
[worker] https://...), and the run’ssteps,tool_calls, tokens andcost_usdare those of the whole tree (as the totals ofgligabao_agent), updated about every half second as the container reports them. When the agent ends, the runs of the sub-agents are imported as runs of their own (children of the run, listed byGET /v1/gb/research?parent_id=; only for runs that had sub-agents), see below. - The knowledge base is the container’s own while the agent works: empty at the start (it is not a copy of the user’s) and gone when the container ends. The
rememberandquerytools work inside the run, and what the agent remembered comes back to the user’s knowledge base when it ends (below); until then provenance and the temporal plot of the admin UI show nothing for the run, and the agent cannot see what the user’s dataset holds. - The keys are the Modal app’s. The container uses the keys of the Modal secret named by
SIDECAR_AGENT_SECRET(ANTHROPIC_API_KEYandOPENAI_API_KEY), not the server’s: the server needs no Anthropic key to start amodalresearch. Themodelmust still support Anthropic’s web search tool. - No per-process limit but the user’s. The limit of 3 agents working at once per user counts the runs in Modal too.
- Stopping (admin UI,
Manager.Stop) asks the sidecar to cancel the job; the container ends the binary (SIGTERM, which ends the research properly;SIGKILLafter 20 seconds) and the run ends asstoppedwhen the job reports it. If the sidecar cannot be reached the run ends asstoppedat once, with a note that the job may go on in Modal until its timeout (SIDECAR_AGENT_TIMEOUT_S, 30 minutes by default). The same happens when the server stops: it asks for the job to be cancelled before it ends the run asfailed(“interrupted”). - A restart of the server does not reattach to the job: runs still
runningare markedfailedwhen it starts again (as for local runs), and a job that is still going in Modal runs until it ends or times out. Its cost is not recorded, and neither is what it learns: nobody is left to download its export. - Failures are as visible as for a local run: a job that dies without reporting (out of memory, the timeout) is closed by the sidecar’s watchdog with a
failedevent, and a follower that cannot reach the sidecar for 5 minutes gives up and ends the run asfailed(“lost contact”). A job may take 3 hours at most.
What comes back (the import)
The container and its storage are gone when the job ends, so the agent hands its state over: the Modal function runs the binary with--export (deep-research-agent.md), stores the archive in the job’s event log (in chunks, before the final event, which says its size and SHA-256), and the sidecar serves it (GET /research/job_export). Also a job that failed or was stopped hands its state over: what it learned until then is kept. When the follower of the run sees the final event it enters the state importing, downloads the archive (3 attempts, checked against the size and the SHA-256), has the importer load it (internal/db/dbimport) and only then ends the run, so a run that says completed already has its knowledge in. A download or import that fails does not fail the run: the report is the result, the importing state carries the error (the export of the agent was not imported: ...) and the log has the details. A server without an importer, or a job with no export (a binary that could not write it), skips the step.
What is loaded, into the databases the server uses (SQLite or PostgreSQL, Chromem or Pinecone), as the user that started the research:
The rows of the relational database go in one transaction: an import that fails leaves it as it was. The vectors and the image files are written after it commits; a failure there is only logged (the rows are in). Importing the same archive twice would add its rows twice, but a run is only imported once. The tables of the ontologies are not imported (an agent has none).
Setting it up.
- Build the agent for the containers:
./run_build.shmakesbuild/gligabao_agent_linux_amd64(a static Linux x86-64 binary, whatever the machine). The sidecar image (Dockerfile.sidecar) builds it itself and has it next toai_train/;SIDECAR_AGENT_BINARYpoints the sidecar at another file. - Create the Modal secret with the keys:
modal secret create gligabao-agent ANTHROPIC_API_KEY=... OPENAI_API_KEY=...and setSIDECAR_AGENT_SECRET=gligabao-agentfor the sidecar. (Without a secret the agent runs without keys and fails with a message saying which one is missing.) - Deploy the Modal app again (the admin UI’s training view, or
modal deploy app.py): the deploy bakes the binary into the agent’s image. An app deployed without the binary has no agent: starting amodalresearch answers503(“this Modal app has no research agent …”). - Start a research with
runner: "modal". The server only needs a reachable sidecar (sidecar_url).
SIDECAR_AGENT_TIMEOUT_S (default 1800) is the timeout of the container’s function; the binary is told to end 90 seconds before it so that it finishes by itself, with a report if it can. More about the Modal side (the function, the event protocol, the configuration) is in training/sidecar.md.
Code: internal/agent_research/remote.go (the Remote and Importer interfaces the manager runs the modal runner and loads its export through, and the follower that writes the job’s events to the run), internal/sys/server/research_remote.go (their implementation over the sidecar client and the server’s databases), internal/db/dbimport (the import), internal/sys/sidecar/research_jobs.go (the client), sidecar/ai_train/ai_train_core/agent_run.py (the container side).
The knowledge base
Besides the web, the agent works with the user’s internal knowledge base (the graph memory of remember and query), through two more tools (details in deep-research-agent.md):remember(text, optionalsource, optionalsync): while it searches the web and reads pages, the agent submits the important parts (short snippets with their context, the URL as the source) to the remember manager, as the user, into the run’s dataset.synctoggles whether the call blocks. By default (sync=false) the call only queues the text and returns at once, so the agent goes on without waiting for it to be absorbed; withsync=trueit waits until the text is in the knowledge base, for when the agent needs it right away (toqueryfor it).query(question): besides web searches and page reads, the agent asks the knowledge base what it knows already, and checks what it found against it. It gets the answer and the facts it is based on. An empty (not yet existing) dataset answers that it is empty.
remember and query endpoints and the session research-<run id>, so they show in the remember run log (gb_remember_runs) and query run log with it. Text that is queued is not tied to the run: it is absorbed even after the run ended, and a failure of it does not fail the run. The cost of these calls is recorded as inferences (gb_inferences) and is not part of the run’s cost_usd.
The investigative loop
An agent whose definition saysloop = "investigative" runs the deep-research loop instead of the simple one (the simple loop is the default and does not change). It works in two phases on a frontier of questions with a notes file, and a run records where it is:
phaseof the run (gb_agent_research_runs.phase):exploration(the cycle on the frontier) orsynthesis(the report is written from the notes, without search tools);''for a run of the simple loop and for runs made before 0.181.0.stop_reason:''while the run explores normally;frontier_exhausted(no actionable question was left and the final check queued nothing),breaker:steps,breaker:tokensorbreaker:cost(a limit ended the exploration; the run is not failed, it writes its report with the cut and the open questions as gaps) are set when exploration ends;finalizedis the reason of a run whose exploration ended by its own gate (finish_exploration) and whose report was accepted. A report that is accepted after a cut keeps the cut as the reason. A breaker that fires in synthesis (the reserve is used up) fails the run, withstop_reasonand theerrornaming the breaker.stepscounts the turns (model calls), and the limit ismax_steps(default 60, 2 to 300 for this loop).
gb_agent_research_states.state) are the ones above plus: planning (the first level of questions is asked for), selecting (the loop picks the next question, no model call; detail frontier_next), extracting (forced extraction: only the notes tools), verifying (an UNVERIFIED claim of the current question has no challenge yet), challenging (a challenge is open), consolidating (the notes are over notes_max_tokens) and synthesizing. The detail of a turn is turn 7 of 60, question q_003. A tool call has its usual state (searching, reading, using_tool, …); fetch_page is reading.
With [code] enabled in the definition the agent also has run_code (agent-defs.md, monty-code-execution.md). Its programs run in a sidecar process (a Python bridge over Pydantic Monty) that the process running the agent starts at the first call and stops with the manager; the settings are monty_python, monty_bin, monty_workers and monty_request_timeout_s of gligabao.toml (or GLIGABAO_MONTY_PYTHON, MONTY_BIN).
The loop keeps the prompt of each turn bounded (the task, the notes, the frontier summary and the last keep_turns turns); a result above extraction_threshold characters forces an extraction turn; and the last turn is forced to call finalize_report. The notes file is notes_<user>_<run>_<notes_id>.md in research_notes_dir; with research_s3_bucket set (also RESEARCH_S3_BUCKET, research_s3_region, research_s3_notes_prefix, default research/investigative_notes) every write is also put to s3://<bucket>/<prefix>/<user>/notes_<user>_<run>_<notes_id>.md (one research bucket for all research agents, a subdirectory per user; a failed put is logged, and a file missing locally is read back from the bucket); if it is missing or differs from the latest stored version, it is rebuilt from gb_agent_notes_versions (reason restore) before the next turn.
Reading a run with SQL
Everything the loop did is in plain tables. In the queries?1 is the run id ($1 on PostgreSQL); they are tested on SQLite (TestInvestigativeRunThroughTheManager).
The frontier as a tree, from parent_id:
survived with one strategy is suspect):
refuted or weakened challenge (the questions and claims it moved; caused_by of a transition holds the challenge id):
state_seq of a version is the seq of the state):
extra, and the phase and stop reason in the trajectory’s result extra. A step that used run_code also has code_runs in its extra: the code, the output, the wall time and the host function calls of each call.
Tracked errors
The key failures of the research agents are recorded asGBerrors in the table gb_errors (internal/sys/errors, see db-tables.md): research.create and research.remote.create (the run could not be recorded), research.recover (restart cleanup failed), research.agent (the agent ended with an error), research.panic, research.finish (the end of the run could not be written), and for runs in Modal research.remote.panic, .timeout, .lost and .finish. The agent loop records agent.tool.panic (a tool panicked; the run goes on with the failure as the tool’s result) and agent.trajectory.store (the trajectory could not be written; the run still succeeds), and the remember tool agent.remember.async (a remember that did not wait failed, so its text is lost). The memory pipelines record remember.pipeline, remember.store.commit, remember.store.vectors, remember.panic, remember.submit.create_run and query.pipeline; cancelled calls are not tracked. A GBerror holds the package, function and stack trace, the op and a small meta map.
Sub-agents
An agent withloop = "investigative" and investigate.max_parallel above 1 runs independent questions of its frontier in sub-agents (workers): the code of the loop starts one for each question, waits for them and reduces their distilled findings into the frontier and the notes. A sub-agent is a run like any other: it has its own states, usage and report, and a parent_id, a name (the question id) and a reason (null/"" for a research a user started); GET /v1/gb/research?parent_id= lists the sub-agents of a run. They are bounded (max_parallel at once, max_workers in the run) and are cancelled when their supervisor ends. The simple loop has no sub-agents (the model-driven ones were removed in 0.189.0). All of it, the findings, the reducer and the limits, is in subagents.md.
How it works
internal/agent: the loop and the research agent (deep-research-agent.md). It has anObserver(before and after each model call and each tool run) that the manager uses to record the states, andReportUsage, with which a tool that calls a model (the web search) adds its tokens and cost to the run.internal/agent_research: theManagermakes aresearcherfor each agent, the struct that holds all of its state (see isolation), and starts it in a goroutine of its own (at most 3 working at once per user); the manager creates the run and its first state in one transaction, and the researcher enters a state in a transaction at each event (end the previous state, insert the new one, set the run’sstate), writes the usage after every model call and tool run, and ends the run (its status, report or error, and the terminal state) in a transaction. A failed write of the progress is logged and does not stop the agent. Storage is inagent_research/db/sqliteandagent_research/db/postgres(each with its schema); the types are inagent_research/core.internal/agent_research/investigative.goandinternal/agent_research/investigate/: the investigative loop (above):loop_state.go,prompt.go,evict.go,gates.goandbreakers.goare pure;loop.gois the effect layer (model, tools, database, notes file);investigative.goconnects it to the researcher (limits from the definition and the options, the states, the usage, the phase).internal/agent_research/workers.go,investigate/delegate.go,investigate_core/delegate.goandinternal/agent/findings.go: the workers of the investigative loop (see subagents.md); the prompt of a worker is ininternal/agent/prompts/.internal/agent/agent_memory/memory.go:Memory(the remember manager, the database, the LLM and the options of the remember and query endpoints), whichapi.Registergives the manager (Manager.UseMemory;agent_research.Memoryis an alias of it); each agent gets its own view of it (Memory.Knowledge: its user, dataset and session) that implementsagent.Knowledge, the interface behind the toolsrememberandquery(internal/agent/knowledge.go). The package is shared with the standalone binary (deep-research-agent.md). Without aMemorythe agents only have the web tools.internal/api/research: the REST handlers;internal/api/mcpandclicall them (the MCP tools in process, the CLI over HTTP).internal/agent_research/remote.go: themodalrunner (above):Manager.UseRemotegives the manager theRemoteit starts the jobs with, and aremoteRunfollows the job of each such run on a goroutine of its own, writing its events to the run like aresearcherdoes, and, when the job ends, downloads its export and has theImporter(Manager.UseImporter; the server’s is ininternal/sys/server/research_remote.go, overinternal/db/dbimport) load it.- When the server stops, the agents are cancelled and their runs are ended as
failed(“interrupted”) before the databases close.
Not included yet
Following again, after a restart of the server, the jobs it had running in Modal (their export, and so what they learned, is lost with them); the user’s own knowledge base for the agents that run in Modal (they start with an empty one of the container’s; what they learn is merged back into the user’s when they end), the import of an export into a server that has no vector store of the same embedding size (the rows are imported, the vectors are not), other places to run the agent than Modal, cancelling a run by a user (only the admin UI can stop one), a stream of its states (pollGET /v1/gb/research/{id}), storing the report itself in a dataset, waiting for the queued snippets before a run ends, counting the cost of remember and query in the run’s cost, recording the agent’s model calls in gb_inferences, and, for the investigative loop, claims, sources and question history in the admin UI, parallel workers on the frontier and sub-agents sharing the notes. See the roadmap.