Skip to main content
GAIA’s agent loop was built for a desktop app that acts on files. Inside a server that answers end users it needs four things set differently. This page is the short list.

A minimal chat agent

Build one agent per request. With skip_lemonade=True construction takes a few milliseconds, and nothing is shared between two agents.

The four settings

GAIA adds one tool of its own, read_tool_output, so the model can page through a result too long to send whole. Pass tool_scope=["get_order", "read_tool_output"] to refuse any call outside that list.

Reading the result

process_query() returns a dict. Decide what to show from status and stop_reason, never from the text.
Show result["result"] to an end user only when status is "success". On any other status it holds GAIA’s own explanation, written for a desktop user, and can name tools, step limits or the raw provider error.

Your own model client

Subclass LLMClient and put it where the agent’s client sits. chat() returns the model’s text, or tool_calls_reply(...) when the model called tools.
Things to know about this seam:
  • Raise your own exceptions. GAIA catches them and ends the turn with status: "failed" and stop_reason: "model_call". Keep the exception on your client if you need its type afterwards.
  • Accept **kwargs. Besides messages, model, stream, tools and max_tokens, the loop can pass temperature, top_p, tool_choice, reasoning_effort and stop. Forward the ones your provider takes.
  • Use a model id with no provider prefix. Ids shaped like provider.model are looked up in Lemonade’s cloud catalogue, and an id it does not list gets its tools as text in the system prompt instead of tools=.
  • Return finish_reason. "length" on a tool call is how GAIA knows the call was cut off and asks for it again.
  • Return usage. The result’s token counts and cost_usd are summed from get_last_usage(), in the OpenAI shape. It must describe the most recent call only, or a step’s tokens are counted twice.

Testing

gaia.testing.ScriptedLLMClient runs the same loop with no network. See Scripting the Model.

What stays your job

  • Budgets. max_steps and max_output_tokens are the limits the loop enforces. Dollar and wall-clock limits belong in your client, between calls.
  • Credentials. Read them from the environment in your client. GAIA’s OS keyring lookup is for desktops.
  • Checking the reply. On a conversation host GAIA sends a reply back only when it is malformed: a tool call or tool output written out as text. Two tries, then the turn ends incomplete with stop_reason: "tool_call_format". Whether the reply is true is yours to check: compare it with tool_calls before it reaches a customer.
  • Hooks you add still run. An answer_problems override, or a mixin such as memory, can still send the model back. Those show up in reprompts.