Skip to content

@Agent

The @Agent decorator defines an LLM-powered workflow node (agents/*.agent.ts) in AGBoss. An agent is a pure declarative class that binds a model, static instructions (prompt or promptUrls), typed Path Scope input fields, structured output DTOs (including oneOf(...) union variants), @Tool and @McpTool capabilities, @Rag knowledge bases, @Judge quality gates, and loop/token limits.

Complete @Agent example with all capabilities

Section titled “Complete @Agent example with all capabilities”

Every @Agent class name ends with Agent and its name option ends with -agent:

Option Type Required Description
name string Yes Unique kebab-case identifier ending with -agent (e.g., "draft-reviewer-agent").
description string Yes Describes the agent’s responsibility for traces, Studio graphs, and CLI inspection.
model string Yes Model identifier (e.g., "moonshotai/kimi-k2.6"); must match a @ModelProvider({ serves }) pattern.
prompt string No* Inline system prompt instructions (*either prompt or promptUrls is required).
promptUrls readonly string[] No* Relative paths to Markdown prompt files (["./reviewer.prompt.md"]) verified at assembly.
promptVariables Readonly<Record<string, string>> No Static {{key}} template values substituted into the agent’s prompt at assembly time.
input InputFields No Map of DTOs read from the workflow’s Path Scope ({ draft: OfferDraftDto, history: historyOf(CritiqueDto, { limit: 3 }) }).
output OutputShape No Structured output DTO class, listOf(Dto), or oneOf(ApprovedDto, ChangesRequestedDto). Defaults to WorkflowFinishTextDto when omitted.
tools readonly Class[] No @Tool and @McpTool classes the agent can invoke during its tool-calling loop.
rag readonly AgentRag[] No Knowledge bases attached as [{ use: DocsRag, mode: RagMode.Tool | RagMode.Context }].
judges readonly Class[] No @Judge classes that verify the agent’s reply and trigger self-correction retries on failure.
maxRetries number No Maximum self-correction retries when a @Judge rejects the agent’s answer.
maxToolCalls number No Maximum tool calls allowed within a single visit to this agent.
maxVisits number No Maximum times a workflow execution may visit this agent (VisitsLimitExceededError).
reasoning Reasoning No Reasoning effort: Reasoning.off(), Reasoning.on({ effort: ReasoningEffort.Low | Medium | High }), or Reasoning.modelDecides().
cache PromptCaching No Prompt caching policy (PromptCaching.off() or PromptCaching.whereSupported({ retention, cachedParts })).
temperature number No Sampling temperature (0 by default).
maxTokens number | TokenLimit No Maximum completion tokens (8192 by default, or TokenLimit.MODEL_MAX).
uncompactedTurns number | TurnLimit No Number of recent conversation turns shown in full to this agent (overrides workflow/app uncompactedTurns).
compaction Class No @Compaction class summarizing older turns for this agent.
piiPolicies readonly Class[] No Additional @PiiPolicy classes applied to this agent’s model and tool calls.
excludePiiPolicies readonly Class[] No Application or workflow @PiiPolicy classes explicitly exempted for this agent.
guardrails readonly Class[] No Additional @InputGuardrail / @OutputGuardrail classes applied to this agent.
excludeGuardrails readonly Class[] No Inherited application or workflow guardrails exempted for this agent.
toolInterceptors readonly Class[] No Additional @ToolInterceptor classes applied to every @Tool and @McpTool invoked by this agent.
excludeToolInterceptors readonly Class[] No Inherited application or workflow @ToolInterceptor classes exempted for this agent.
price { input: number; output: number } No Custom USD price per 1M input/output tokens overriding the provider’s cost table.
Related Entity Import Path Purpose
oneOf(DtoA, DtoB), listOf(Dto), optional(Dto), historyOf(Dto, { limit }) "@agboss/core" Declares union output variants, list outputs, optional inputs, and bounded loop histories.
Reasoning & PromptCaching "@agboss/core/models" Configures reasoning effort (Reasoning.on({ effort })) and prompt caching (PromptCaching.whereSupported()).
RagMode (Tool, Context) "@agboss/core" Controls whether a @Rag knowledge base is exposed as a callable search tool or injected into context automatically.
VisitsLimitExceededError "@agboss/core" Thrown before the model call when an agent exceeds maxVisits in a review loop; catchable via .onError().
mockLlm(AgentClass) & replyWith(Dto, value) "@agboss/core/testing" Scripts deterministic agent responses, tool calls (callTool), and simulated latency (waitFor) in testWith() tests.