Build an agent-backed bound operation
Use this pattern when the application owns identifiers and exact operations, but a bounded semantic choice belongs to the agent. The example uses the keyless test model and a harmless local operation. Keyless does not mean dry-run: capability code executes for real. Never attach destructive or privileged operations to a test-model endpoint.
Version 0.15.0 bounded repeated calls
Section titled “Version 0.15.0 bounded repeated calls”One required typed operation may run a finite positive number of times (1 <= minimum <= maximum, maximum > 1) with a Pydantic request, at least one FromRequest, direct closed Literal[str] AgentChoice inputs, supported request/context bindings or immutable defaults, and exact full operation-output/endpoint-response annotation identity. Summonpot owns sequential decisions; business functions are not selector tools. It locally validates selections, shares one usage budget and deadline, resolves the model lazily, auto-finishes at maximum, and returns only the final successful canonical result; any failure aborts. Previous-result evidence is limited to 65,536 characters per decision, not an aggregate prompt budget. Explicit tool_calls_limit fails before provider/effects. No producer choices, FromResult, after, zero-minimum/unbounded bounds, implicit batch, or general graph. Existing Exactly(1) and producer-choice routes remain unchanged. Published v0.14.0 is untouched; milestone 3 remains partial and a narrow repeated-stage consumer is now documented below. Broader repeated-result addressing remains planned.
Version 0.15.0 repeated-stage final-result consumer
Section titled “Version 0.15.0 repeated-stage final-result consumer”The original two-operation form lets one bounded repeated producer feed one required, choice-free terminal operation after the producer stage closes. The terminal uses FromResult(producer, field, invocation="final") to bind the final successful canonical result from one immutable closure record; meeting the minimum alone does not make it ready, and a failed or uncertain invocation aborts without earlier-result fallback. This two-operation shape is version 0.15.0, not published v0.14.0 behavior. It does not add aggregation, repeated consumers, inspect/correct/verify workflows, or general graphs. See the repeated-stage contract.
Version 0.15.0 single-stage sequential chains
Section titled “Version 0.15.0 single-stage sequential chains”Version 0.15.0 supports a uniquely ordered chain with one nonterminal bounded repeated operation, an optional resolved prefix and a nonempty resolved suffix. Every other operation is required Exactly(1) with no agent choices. A Pydantic request needs at least one FromRequest across the whole chain, not necessarily on the repeated operation; supported request/result/authenticated-context bindings and immutable defaults remain required. The repeated operation has positive finite bounds (minimum >= 1, maximum > 1), direct closed plain-string Literal choices and a Pydantic intermediate distinct from the response. Ordinary FromResult reads single-invocation results; repeated results require invocation="final", with at least one suffix consumer. Exactly one terminal operation owns the endpoint’s exact full response annotation. Prefix operations run before one lazy model resolution; suffix operations run after immutable stage closure without further model decisions or acknowledgment. One principal, ledger, absolute deadline and usage budget span the request. Prefix results/context/ledger are not implicitly projected into model prompts; receiving constraints are checked before each start. Explicit function-tool quotas reject before all work. No feedback cycles, external choices, multiple repeated stages, aggregation, parallelism or durable recovery are added. Published behavior before v0.15.0 remains unchanged. See the single-stage chain contract.
Version 0.15.0 prefix selection before repetition
Section titled “Version 0.15.0 prefix selection before repetition”Version 0.15.0 also composes exactly one producer-backed choice argument on one required Exactly(1) prefix consumer with one nonterminal bounded repeated stage and a resolved suffix. The candidate producer is an earlier single-start operation returning list[ConcreteModel]; repeated choices remain direct closed string Literal values, and all other operations remain resolved required Exactly(1). Pydantic request/response, chain-wide FromRequest, unique ordering, final-invocation addressing and exact terminal response ownership remain required. Empty/unavailable/oversized candidate domains stop before selection or repeated work; a singleton binds locally, while ambiguity uses canonical request-local tokens. Singleton selection still leads to model-backed repeated decisions. One lazy model-configuration lookup, run, principal, ledger, deadline and usage budget span both phases. No business-function tools, reselection after same-run failure, effect replay or final model acknowledgment are added. A fresh request starts a fresh run. Published behavior before v0.15.0 remains unchanged. See the composed selection/stage contract.
See the canonical contract.
Version 0.15.0 framework-owned progression
Section titled “Version 0.15.0 framework-owned progression”Version 0.15.0 supports one or more producer-backed choices with framework-owned progression. In an otherwise eligible uniquely ordered required Exactly(1) chain, a Pydantic request, at least one FromRequest, supported request/result/authenticated-context bindings or immutable defaults, and exact full terminal response annotation identity remain required. All current consumer domains are checked before selection or start. Singleton bindings resolve locally; a decision-only selector returns ambiguous tokens with no business-operation tools. The shared kernel validates and invokes the operation, then continues locally until another genuine decision is needed. The canonical terminal result returns without a final model acknowledgment. Request/principal, reservations, token domains, usage budgets and one deadline remain request-local across frontiers and corrections. Explicit tool_calls_limit retains the previous one-way agent suffix; allow_direct=False and other noneligible declarations retain their existing route. Limits remain 128 candidates and 65,536 evidence characters per binding, not an aggregate prompt/context budget. Prefix effects may precede provider-configuration failure; no rollback, effect replay or durable resume is added. Historical v0.14.0 remains exactly-one-choice. See the operation reference for details.
Complete example
Section titled “Complete example”Install summonpot[serve] and save as agent_summary.py:
from typing import Literal
from pydantic import BaseModel, Fieldfrom summonpot import AgentChoice, Exactly, FromRequest, Operation, Required, Summon
class SummaryRequest(BaseModel): topic: str = Field(min_length=1, max_length=200)
class SummaryResponse(BaseModel): summary: str style: Literal["brief", "detailed"]
def build_summary(topic: str, style: Literal["brief", "detailed"]) -> SummaryResponse: """Build a deterministic local summary candidate.""" limit = 80 if style == "brief" else 240 return SummaryResponse(summary=topic[:limit], style=style)
summary_operation = Operation( build_summary, bind={"topic": FromRequest("topic"), "style": AgentChoice()}, output=SummaryResponse,)
summon = Summon("summary-api")
@summon("/summarize")def summarize( request: SummaryRequest, result=Required(summary_operation, calls=Exactly(1)),) -> SummaryResponse: """Summarize the request topic and choose a brief or detailed style.""" ...
if __name__ == "__main__": summon.serve(host="127.0.0.1", port=8000)Run the local server:
SUMMONPOT_MODEL=test python agent_summary.pyCall the public HTTP route from another terminal:
curl -i -X POST http://127.0.0.1:8000/summarize \ -H 'Content-Type: application/json' \ -d '{"topic":"A concise contract separates trusted request data from bounded choices."}'The test model supplies placeholder agent output, not a useful semantic answer; the operation still runs. The response must validate as SummaryResponse, and Required means the operation must succeed before a successful final output. Do not treat the final text as proof that it reproduces the operation result: local schema validation constrains shape and types, not semantic provenance.
Follow the authority boundary
Section titled “Follow the authority boundary”SummaryRequestvalidates caller input.FromRequest("topic")injects that validated topic; it is absent from the model-visible operation arguments.AgentChoice()is the only model-controlled argument in this declaration. It grants a choice within the registeredbuild_summarycallable, not permission to select another function or trusted customer identity.Required(..., calls=Exactly(1))sets the mandatory operation and call bound. Runtime state enforces the bound; the prompt alone is not enforcement.output=SummaryResponsevalidates operation output before it can count as a successful required call. The endpoint response is separately validated.
Operation outputs and valid-looking final responses do not imply authorization, atomicity, idempotency, exactly-once completion, or a causal link between returned text and operation result. Enforce access control in the operation; design retries and side effects explicitly.
Common mistakes
Section titled “Common mistakes”- Do not make a customer ID an
AgentChoice; bind trusted request fields and authorize them in application code. - Do not expect keyless model output to exercise the semantic behavior of a real provider. This is a wiring check, not quality evaluation.
- Do not expose shell, raw database connections, arbitrary SQL, or broad service objects as capabilities.
- Do not assume a failed output validation undoes an operation that already had side effects.
- Do not switch to
Operation(fn)with missing bindings to get a permissive fallback; unsupported explicit declarations fail at registration.
Limits of the shipped slice
Section titled “Limits of the shipped slice”The runtime-enforced bound-operation slice supports the explicit FromRequest and direct AgentChoice binding vocabulary with compatible receiving types and exact output contracts. The no-model path is stricter and permits no unresolved AgentChoice. Bare callable dependencies remain on the legacy agent path. FromResult and after are supported in uniquely ordered chains, and current unreleased source additionally admits one producer-backed choice in the narrow required-DAG exception described in the operation reference. Fully resolved chains execute model-free from 0.12.0 with a Pydantic request, at least one FromRequest binding, supported sources, and an exact full terminal response annotation. An AgentChoice normally keeps the chain agent-mediated; the result-dependent source exception included from version 0.14.0 is documented in the operation reference. Published behavior remains unchanged. Authenticated FromContext is supported from version 0.13.0 in a narrow source slice; broader graph execution remains planned/rejected. See the reference and roadmap.
For exact model-free execution, use Build a model-free endpoint. For provider/runtime setup and HTTP errors, see Operations and troubleshooting.