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 withawait agent.run(inputs), passing the typed input when the agent declaresinput_typeand none when it does not, and files produced during the step asattachments=[...], which follow the declared prompt. An editor checks the input againstinput_type.agent(...)without.runis rejected in a step, a tool and a workflow body. Every text part is a Handlebars template over the typedinputsobject (computed fields included): paths ({{claim.patient.name}},{{pages.0.content}}), blocks ({{#if hints}}...{{/if}},{{#each pages}}[{{@index}}] {{this.content}}{{/each}}), and thejsonhelper ({{json output_schema}}) for embedding a field as pretty-printed JSON. Never Pythonstr.formatbraces. Rendering is strict: a path missing from the inputs fails the run. Deploy checks the template against the agent’sinput_type; an agent without one runs with no input, so its prompt references no field.promptis 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 underandon/prompts/.- Output contract:
output_type=Model, a discriminated union such asCompleted | NeedsReview | Rejected, oroutput_schema_field="field"(a JSON Schema dict carried in a field ofinput_type), never both forms. Omit both for free-textstroutput with no typed validation. - Agents without
code_moderequire finite, non-recursive output schemas for bothoutput_typeandoutput_schema_field. The same requirement applies toctx.promptwithoutput_type=oroutput_schema=. - In a structured model response (an agent without
code_mode, orctx.promptwithoutput_type=oroutput_schema=) and in the arguments a model passes to a@tooloutside 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 (anoutput_typemodel or a tool parameter) applies its Python default ordefault_factory: forvalue: int | None = 7, a null yields{"value": 7}. A raw JSON Schema (output_schema=oroutput_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-modeSUBMIT(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@toolfunctions. 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_factoryvalues are frozen at first materialization. Replay restores completed model/tool results without repeating their side effects or spend. retries=Nis 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_callscounts agent turns, authoredctx.promptcalls andllm_querycalls. Model calls managed by other platform tools, such asstructured_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=Truegives the model a Python REPL; load typed inputs withget_inputs()and finalize viaSUBMIT(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_fieldproperties on the input model for context that is genuinely computed (aggregations, derived timelines), referenced like any other field. FileReffields are first-class typed agent inputs and render asandon://...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 typeddocumentargument ofparse_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 theFileReffield ofinputs.jsonand runandon runs start <workflow_key> --input-file inputs.json. The CLI resolves relative paths from the directory containinginputs.jsonand uploads the file before starting the run. To reuse one upload across runs, useandon files upload <path>. API clients upload withPOST /api/filesand 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.