Skip to content
Andon Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Agents and models

Define an agent's inputs, prompt and output, choose a model family, and validate what it returns.

Define an agent’s inputs, prompt and output, choose a model family, and validate what it returns.

Agents

Agents run on the platform; a step or tool body awaits agent.run(...).

Canonical declaration and call shape:

from dataclasses import dataclass

from andon_dsl.agents import Agent, StrategyFile
from andon_dsl.workflows import step, workflow


@dataclass
class SummaryInput:
    text: str


@dataclass
class Summary:
    title: str
    key_points: list[str]


summarizer = Agent(
    model_family="small",
    input_type=SummaryInput,
    output_type=Summary,
    system_instructions=StrategyFile("../prompts/summarize.md"),
    prompt="Summarize {{text}}.",
)


@step
async def summarize(input: SummaryInput) -> Summary:
    return await summarizer.run(input)


@workflow
def summarize_text(input: SummaryInput) -> Summary:
    return summarize(input)
  • prompt= declares the user message every call sends: text, ImageContent, DocumentContent, or a mixed list. A step or tool body runs the agent with await agent.run(inputs), passing the typed input when the agent declares input_type and none when it does not, and files produced during the step as attachments=[...], which follow the declared prompt. An editor checks the input against input_type. agent(...) without .run is rejected in a step, a tool and a workflow body. Every text part is a Handlebars template over the typed inputs object (computed fields included): paths ({{claim.patient.name}}, {{pages.0.content}}), blocks ({{#if hints}}...{{/if}}, {{#each pages}}[{{@index}}] {{this.content}}{{/each}}), and the json helper ({{json output_schema}}) for embedding a field as pretty-printed JSON. Never Python str.format braces. Rendering is strict: a path missing from the inputs fails the run. Deploy checks the template against the agent’s input_type; an agent without one runs with no input, so its prompt references no field. prompt is required. Text that varies per call is an input field. Write a literal {{ as \{{. Template paths always use Python field names; validation aliases are accepted on JSON input and serialization aliases are used on returned results, but neither changes names inside prompts or workflow execution.
  • system_instructions=StrategyFile("../prompts/name.md"): the path is relative to the defining file and must land under andon/prompts/.
  • Output contract: output_type=Model, a discriminated union such as Completed | NeedsReview | Rejected, or output_schema_field="field" (a JSON Schema dict carried in a field of input_type), never both forms. Omit both for free-text str output with no typed validation.
  • Agents without code_mode require finite, non-recursive output schemas for both output_type and output_schema_field. The same requirement applies to ctx.prompt with output_type= or output_schema=.
  • In a structured model response (an agent without code_mode, or ctx.prompt with output_type= or output_schema=) and in the arguments a model passes to a @tool outside code mode, a property the model may omit is presented to it as nullable, and a returned null is treated as omission. What omission yields depends on the contract. A typed contract (an output_type model or a tool parameter) applies its Python default or default_factory: for value: int | None = 7, a null yields {"value": 7}. A raw JSON Schema (output_schema= or output_schema_field) leaves the property out, because a schema "default" is an annotation and is not filled in: the same null yields {}. Either way, a property that is both nullable and omittable cannot receive an explicit null there. A required nullable property keeps null. A code-mode SUBMIT(result=...) and tool calls made from code cells use ordinary validation: an explicit null stays null where the contract allows it, and an omitted value takes its Python default under a typed contract, while a raw JSON Schema "default" stays an annotation.
  • tools=[...] is the single opt-in surface for platform tools, toolset members, and user-defined @tool functions. A tool is unavailable to the agent unless it appears in this list.
  • Every agent checkpoints canonical inputs and inner model/tool calls. Input default_factory values are frozen at first materialization. Replay restores completed model/tool results without repeating their side effects or spend.
  • retries=N is the model’s repair budget for tool-call feedback and output validation (output_retries= splits the latter). Exhaustion fails the run with a user-readable message naming the budget.
  • Agent(usage_limits=UsageLimits(...)) caps one agent invocation. @workflow(..., usage_limits=UsageLimits(...)) adds a parent cap shared by direct step prompts, every fanout element, and nested or supervisor agents. max_llm_calls counts agent turns, authored ctx.prompt calls and llm_query calls. Model calls managed by other platform tools, such as structured_extract, are exempt from this call limit. Every model call counts toward token limits and billing. Nested agents use their own agent cap and the shared workflow cap. Token budgets are checked against a request’s estimated input before it is sent and against reported usage after each response. Usage is counted from zero each time a worker starts or resumes the run: after a wait, a sleep, or an infrastructure retry, steps that already completed are not counted again. A workflow cap therefore bounds each uninterrupted stretch of work, not the run’s total across resumptions.
  • ModelSettings(...) is a closed typed contract. Unknown provider-specific request fields fail authoring and deployment validation.
  • code_mode=True gives the model a Python REPL; load typed inputs with get_inputs() and finalize via SUBMIT(result=...) in a cell.
  • Put prompt structure in the template: embed typed objects with {{json claim_context}}, gate optional sections with {{#if ...}}, enumerate collections with {{#each ...}}. Reserve @computed_field properties on the input model for context that is genuinely computed (aggregations, derived timelines), referenced like any other field.
  • FileRef fields are first-class typed agent inputs and render as andon://... URI strings. Reference the field directly as {{file}} or embed a containing object with {{json document}}, then instruct the model to pass the URI unchanged as the typed document argument of parse_document / search_document. The runtime resolves the reference within the run’s organization scope; file metadata and bytes do not belong in the prompt.
  • Keep workflow and agent inputs typed as FileRef. The console accepts a file directly. With the CLI, put the document path in the FileRef field of inputs.json and run andon runs start <workflow_key> --input-file inputs.json. The CLI resolves relative paths from the directory containing inputs.json and uploads the file before starting the run. To reuse one upload across runs, use andon files upload <path>. API clients upload with POST /api/files and put the returned file reference in the JSON run input.

Model families and thinking

Agent defaults to model_family="medium". Use small for classification and routing, medium for extraction and reasoning, and large for verification or the hardest cases. Authors choose a family; the platform resolves its provider model.

ctx.prompt defaults to model_family=None: inside an agent it inherits that agent’s model; in a standalone workflow step it selects medium. A named family always selects that family. For example, an explicit ctx.prompt(..., model_family="medium") inside a large agent selects the platform’s medium model. The omitted argument and explicit None have the same meaning.

ModelSettings(thinking=...) accepts none, low, medium, high, xhigh, and max. The resolved model must support the requested level; unsupported levels fail with a user-readable error before sending a request. The launch GPT-5.6 models accept every level; Astra requires at least low. Omitting thinking uses the provider’s default.

Output validators

In Agent(output_validators=[fn]), each validator must be a named module-level function. It receives (inputs, output) after type/schema validation. Raise AgentRetryError to send the model repair feedback; return a replacement output to normalize it; return None to keep it. Ordinary exceptions (including ValueError) are treated as validator bugs and fail the run.

Validators must be deterministic in (inputs, output): durable replay re-validates cached model outputs, so a validator that consults the clock, the network, a file, or any mutable state will pass the live run and fail its replay with no useful diagnostic. If a check needs reference truth (catalogs, cutoff dates), compute it in an upstream step and carry it on the agent’s inputs; the validator then compares output claims against inputs.<truth> and stays pure.

Was this page helpful?