task.llm for making language model calls. Guild resolves the provider and model from the workspace owner’s LLM settings — your agent code doesn’t need to specify them.
LLM usage is subject to per-execution budgets: request payload size, call count, and token count. Exceeding a budget fails the call with a
429 Too Many Requests error. See Execution limits.Basic usage
Structured generation
Pass a Zod schema to get typed, validated output:Single model call
generateText makes one model call and returns. There is no maxSteps and no stopWhen, so there is no built-in ReAct loop. If you pass tools with an execute function those tools run and result.toolResults may be populated — but the model is never called again with those results. A turn that ends in a tool call returns with finishReason: "tool-calls" and text that stops mid-thought.
If the agent must call a tool, read what it returned, and continue, write that loop yourself:
dispatch and asToolResultContent are yours to write — the first runs the calls, the second shapes them into tool-result content parts.
Bound the loop clear of normal use: a ceiling a legitimate request can reach truncates that request silently. If you would rather not write the loop, llmAgent is the managed version, and a self-managed agent’s start() / onToolResults() pair lets the runtime drive the round trip. Hand-roll only when you need control over each step.
Best practices
- Cache results. Store the return value of
generateText()in a variable if you need it more than once. Each call costs tokens. - Be specific in prompts. Clear, detailed prompts produce better results and reduce the need for follow-up calls.
- Use schemas for structured data. When you need specific fields, pass a schema rather than parsing free-form text.
- Keep prompts focused. One clear task per call is better than a complex multi-part prompt.
LLM preferences
UsellmPreferences to express an ordered list of LLM provider/model preferences for a generateText call. Guild resolves the list against the account’s LLM configuration: for accounts that bring their own keys (BYOK), against the account’s keys and model policies; for managed accounts, against server-side authorizations.
Preferences are strict. If you declare preferences and none of them can be used — no key or policy allows any preferred model — the call fails with an error naming the refused preferences. Guild never silently substitutes the account’s default model for a declared preference. Omit llmPreferences to use the account’s default configuration.
model to let the server choose a model from the matching policy; a provider-only entry that matches the account’s configured provider resolves to that provider’s default model.
Each entry is an LLMPreference object:
llmAgent also accepts llmPreferences with the same semantics. See TypeScript LLM agents.
Configuration
The provider and model are resolved at runtime from the workspace owner’s LLM settings, not in agent code. For a workspace owned by your user account, use Settings > LLM Settings. For an organization workspace, organization admins configure Settings > LLM Settings on the organization. This means:- Your agent code does not include API keys or provider names
- Changing LLM settings in the console updates behavior without redeploying agents
- Workspaces with different owners can use different LLM configuration with the same agent code
Unified LLM proxy
When your agent code already targets the OpenAI API — for example, code running inside a coding container — you can point it at the runtime’s built-in LLM proxy instead of a provider directly. Guild routes each request to the provider configured in the workspace’s LLM settings and translates the request and response as needed. Your code targets one interface regardless of the active provider. The proxy endpoint accepts the OpenAI chat completions format and is available inside the agent task environment at the path/runtime/services/llm/chat/completions.
Provider support
Developer role
OpenAI’sdeveloper role messages are automatically folded into the system prompt. You do not need to adjust your message structure when switching providers.
Error handling
Errors are returned as standard OpenAI error shapes:Reasoning progress
Reasoning progress exposes the model’s thinking stream while it works. When the selected model supports it and the runtime has it enabled, Guild publishes the stream to the session’s task block and calls youronReasoningDelta handler on each delta.
GenerateTextStreamOptions: