Skip to main content
Every agent has access to 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.

Basic usage

const result = await task.llm.generateText({
  prompt: "Summarize this text...",
})

// result.text contains the model's response
console.log(result.text)

Structured generation

Pass a Zod schema to get typed, validated output:
import { z } from "zod"

const result = await task.llm.generateText({
  prompt: "Extract the key details from this issue...",
  schema: z.object({
    severity: z.enum(["low", "medium", "high"]),
    summary: z.string(),
    affectedFiles: z.array(z.string()),
  }),
})

// result is typed according to your schema
console.log(result.severity) // "high"

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.

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