Skip to main content
Every agent callback — run, start, onToolResults, init — receives a Task object as its last argument. The task is your agent’s interface to the Guild runtime: it exposes services for calling platform endpoints, talking to the user, logging, and persisting state.
async function run(input: Input, task: Task<Tools>): Promise<Output> {
  // task.sessionId, task.console, task.tools
  // task.guild, task.ui, task.llm
  // task.save, task.restore
}
The shape of task is conditional on the Tools type: task.guild is typed as GuildService only when Tools structurally extends GuildToolSet, and task.ui is UserInterfaceService only when Tools extends UserInterfaceToolSet. Including the corresponding tool set in your agent’s tools is how you “turn on” the service.

Typical usage

Most agents only need a handful of services. Here’s a small agent that uses task.console, task.ui, and task.guild:
import {
  agent,
  guildTools,
  progressLogNotifyEvent,
  userInterfaceTools,
  type Task,
} from "@guildai/agents-sdk"
import { z } from "zod"

const inputSchema = z.object({ workspace_id: z.string() })
const outputSchema = z.object({
  workspace_name: z.string(),
  context_count: z.number(),
})

const tools = { ...guildTools, ...userInterfaceTools }
type Tools = typeof tools

async function run(
  input: z.infer<typeof inputSchema>,
  task: Task<Tools>,
): Promise<z.infer<typeof outputSchema>> {
  "use agent"
  task.console.info({ sessionId: task.sessionId }, "starting run")

  await task.ui.notify(progressLogNotifyEvent("Fetching workspace..."))
  const workspace = await task.guild!.get_workspace({
    workspace_id: input.workspace_id,
  })

  await task.ui.notify(progressLogNotifyEvent("Checking context history..."))
  const { items } = await task.guild!.get_workspace_contexts({
    workspace_id: input.workspace_id,
    limit: 100,
  })

  return { workspace_name: workspace.name, context_count: items.length }
}

export default agent({
  description: "Typical task usage.",
  inputSchema,
  outputSchema,
  tools,
  run,
})

task.sessionId

The opaque session identifier for the current agent run. Use it to correlate logs, emit metrics, or pass to endpoints that take a session id.
task.console.debug({ sessionId: task.sessionId }, "starting work")

task.console — debug logging

task.console is always available and never requires a tool set. Use it for printf-style debugging visible in the runtime logs. Each level accepts either a message string, an object + message, or arbitrary variadic arguments.
MethodDescription
debug(msg or obj, ...args)Debug-level message
info(msg or obj, ...args)Info-level message
warn(msg or obj, ...args)Warning message
error(msg or obj, ...args)Error message
log(msg or obj, ...args)Alias for info
console_log({ level, message })Structured variant matching the console_log tool
await task.console.debug({ input }, "received request")
await task.console.error("aborting: invalid state")
To expose debug logging to an LLM, include consoleTools in your agent — the LLM can then call console_log as a regular tool.

task.tools — invoke your tools directly

task.tools is a typed proxy over every tool declared in the agent’s tools set. Calling task.tools.foo(args) dispatches to the tool and returns its output with the tool’s declared output type.
const workspace = await task.tools.guild_get_workspace({
  workspace_id: "ws_123",
})
This works for any tool, whether it’s a built-in tool set (guildTools, userInterfaceTools, …), a third-party service tool (gitHubTools), or a custom tool created with guildServiceTool / guildAgentTool.

task.ui — user interaction

Available when Tools includes userInterfaceTools. task.ui is a UserInterfaceService that can send notifications, ask the user for input, or ping the front-end.
MethodDescription
notify(event)Fire-and-forget notification. Use the event helpers listed below.
prompt({ type: "text", text })Block until the user replies with text.
ping({ message })Health-check the UI surface (mostly for testing).

Notify event helpers

notify takes a discriminated NotifyEvent. Three helpers in @guildai/agents-sdk construct the common shapes:
HelperEvent typeUse for
progressLogNotifyEvent(text)progressNon-intrusive “Creating…”, “Running…” status updates during long work
textPromptNotifyEvent({ type: "text", text })messageA regular message posted to the conversation
errorNotifyEvent(error)errorProminently-displayed error condition
import {
  progressLogNotifyEvent,
  textPromptNotifyEvent,
  errorNotifyEvent,
} from "@guildai/agents-sdk"

await task.ui.notify(progressLogNotifyEvent("Creating environment..."))
await task.ui.notify(
  textPromptNotifyEvent({ type: "text", text: "Here's what I found." }),
)
await task.ui.notify(errorNotifyEvent("Failed to reach GitHub"))

Prompting the user

task.ui.prompt blocks the agent until the user replies. It’s the imperative counterpart to the ask(...) helper used by self-managed agents.
const reply = await task.ui.prompt({
  type: "text",
  text: "Which language should I use?",
})
// reply.text contains the user's answer

Progress log best practices

  • Use present continuous tense: “Creating…”, “Running…”, “Writing…”
  • Keep messages to one line
  • Be specific: “Writing 3 files…” rather than “Processing…”
  • Log at meaningful milestones, not on every iteration

task.llm — LLM calls

task.llm always exposes an LLMService. The runtime handles authentication and provider selection, so you don’t need to pass API keys or pick a model explicitly.
MethodDescription
generateText(params)Call the workspace’s configured LLM. Returns { text, content, toolCalls, toolResults, finishReason, response }.
generateText takes either a single prompt or a messages array, never both:
const result = await task.llm.generateText({
  prompt: "Summarize this file:\n\n" + source,
})
// result.text — plain-text summary

const chat = await task.llm.generateText({
  system: "You are a concise assistant.",
  messages: [
    { role: "user", content: "What is Guild?" },
  ],
})
Pass tools to generateText if you want the LLM to request tool calls; the returned toolCalls array lists what it decided to invoke.

task.save / task.restore — state persistence

Used by SelfManagedStateAgent (and available to automatic-state agents too):
MethodDescription
save(state)Persist state to the runtime. Must match stateSchema and be JSON-serializable.
restore()Read the previously-saved state, or undefined if nothing is saved yet.
State is scoped to the current task, and is retained across suspensions (e.g., while waiting for user input).

task.guild — platform operations

Available when Tools structurally includes GuildToolSet. task.guild is a GuildService that exposes the full Guild platform API — workspaces, agents, triggers, credentials, sessions, and escape hatches like experimental_fetch. Because task.guild is conditionally typed, TypeScript types it as GuildService | undefined until it can prove your tool set includes guildTools. A common pattern is to assert non-null with ! after ensuring guildTools is in the spread:
const tools = { ...guildTools }
// ...
const { items } = await task.guild!.get_workspace_contexts({
  workspace_id: input.workspace_id,
  limit: 10,
})
The 50+ endpoints below are grouped by theme. All of them take a single params object and return a structured response; each takes a single params object and returns a structured response.

Current user

EndpointDescription
get_meFetch the authenticated user’s profile
update_meUpdate the authenticated user’s profile
get_my_workspacesList workspaces owned by or visible to the current user
get_my_organizationsList organizations the current user belongs to
get_my_sessionsList recent sessions for the current user

Users

EndpointDescription
search_usersFull-text search across users
get_userLook up a specific user by id
get_user_organizationsList organizations a user belongs to
get_user_agentsList agents a user has authored
get_user_workspacesList workspaces a user can access

Agents

EndpointDescription
list_agentsPaginated list of agents
search_agentKeyword search across agents
check_agent_nameCheck whether an agent name is available
get_agentFetch a single agent by id
create_agentCreate a new agent
update_agentUpdate an existing agent
get_agent_codeRead the source code of an agent version
list_agent_versionsList historical versions of an agent
create_agent_versionPublish a new version of an agent
get_agent_versionFetch a specific version by id
revalidate_agent_versionRerun validation on an existing version
list_agent_tagsList tags attached to an agent
update_agent_tagsReplace the set of tags on an agent
generate_agent_avatarGenerate an avatar image for an agent

Agent likes

EndpointDescription
create_agent_likeLike an agent on behalf of the current user
delete_agent_likeUnlike an agent
list_agent_likersList the users who have liked a given agent
list_agent_workspacesList the workspaces that have installed a given agent

Organizations

EndpointDescription
get_organizationFetch an organization by id
update_organizationUpdate an organization
get_organization_workspacesList workspaces in an organization
get_organization_agentsList agents in an organization
get_organization_membersList members of an organization

Workspaces

EndpointDescription
get_workspaceFetch a workspace by id
get_workspace_agentsList agents installed in a workspace
get_workspace_sessionsList sessions in a workspace
get_workspace_contextsList versions of the workspace context (newest first)
create_workspace_contextAppend a new DRAFT or PUBLISHED workspace context version

Triggers

EndpointDescription
get_workspace_triggersList triggers in a workspace
create_workspace_triggerCreate a new trigger
get_triggerFetch a trigger by id
update_triggerUpdate a trigger
activate_triggerEnable a trigger
deactivate_triggerDisable a trigger
get_trigger_sessionsList sessions created by a trigger

Sessions & tasks

EndpointDescription
get_sessionFetch a session by id
get_task_workspace_agentsList workspace agents available to the current task (used internally by llmAgent)

LLM usage

EndpointDescription
get_daily_llm_usageDaily token usage rollups
get_hourly_llm_usageHourly token usage rollups

Credentials & install hooks

These endpoints may suspend the agent while waiting for a user or GitHub to respond.
EndpointDescription
agent_install_requestAsk the user to install another agent into the workspace
credentials_requestAsk the user to authorize a third-party service (e.g., Linear, GitHub)
experimental_github_installation_tokenMint a GitHub installation token for the current workspace

Flow control & HTTP

EndpointDescription
sleepSuspend the agent for N seconds (may round-trip the runtime)
experimental_fetchSynchronous HTTP request
experimental_fetch_asyncAsync HTTP request — result arrives via a hook when complete

Service availability

PropertyWhen available
task.sessionIdAlways
task.consoleAlways
task.toolsAlways — contains your declared tools
task.llmAlways
task.save / task.restoreAlways
task.uiRequires userInterfaceTools in tools
task.guildRequires guildTools in tools