SummonpotModePot

Contract playground

A fixed request. A bounded choice.

The request owns the customer ID. Only the display format is available for an agent to choose.

Here, you select that allowed choice yourself. No agent or Python server runs.

  1. 01
    Request fixes the IDFromRequest
  2. 02
    Choice stays within two formatsAgentChoice
  3. 03
    Application runs one lookupExactly(1)
examples/07_bound_operation.pyView source ↗
def load_customer(
    customer_id: str,
    format: Literal["summary", "detailed"],
) -> CustomerRecord:
    ...

customer_lookup = Operation(
    load_customer,
    bind={
        "customer_id": FromRequest("customer_id"),
        "format": AgentChoice(),
    },
    output=CustomerRecord,
)

@summon("/customers/view")
def customer_view(
    request: CustomerRequest,
    customer=Required(customer_lookup, calls=Exactly(1)),
) -> CustomerView:
    """Load the requested customer once and return a concise approved view."""
    ...

Shipped signature and declaration · lookup body omitted.

Complete shipped example
"""Level 7: one exactly-once operation with mixed argument authority."""

from typing import Literal, TypedDict

from pydantic import BaseModel

from summonpot import (
    AgentChoice,
    Exactly,
    FromRequest,
    Operation,
    Required,
    Summon,
)


class CustomerRequest(BaseModel):
    customer_id: str


class CustomerRecord(BaseModel):
    customer_id: str
    name: str
    status: Literal["active", "paused"]
    format: Literal["summary", "detailed"]


class CustomerView(BaseModel):
    customer_id: str
    display: str


class _Customer(TypedDict):
    name: str
    status: Literal["active", "paused"]


_CUSTOMERS: dict[str, _Customer] = {
    "customer-7": {"name": "Ada", "status": "active"},
    "customer-9": {"name": "Grace", "status": "paused"},
}


def load_customer(
    customer_id: str,
    format: Literal["summary", "detailed"],
) -> CustomerRecord:
    """Load one approved customer record in the selected display format."""
    record = _CUSTOMERS[customer_id]
    return CustomerRecord(
        customer_id=customer_id,
        name=record["name"],
        status=record["status"],
        format=format,
    )


customer_lookup = Operation(
    load_customer,
    bind={
        "customer_id": FromRequest("customer_id"),
        "format": AgentChoice(),
    },
    output=CustomerRecord,
)

summon = Summon("bound-customer-service")


@summon("/customers/view")
def customer_view(
    request: CustomerRequest,
    customer=Required(customer_lookup, calls=Exactly(1)),
) -> CustomerView:
    """Load the requested customer once and return a concise approved view."""
    ...


if __name__ == "__main__":
    summon.serve(host="127.0.0.1", port=8000)
Try the declared boundary

Application-owned operation result

Ready to run

BROWSER PREVIEW

The operation result will appear here.

Customer ID
—
Customer
—
Status
—
Chosen format
—
Inspect the bound arguments
  1. Validate request
  2. Bound format choice
  3. Required lookup × 1
  4. Typed operation result

Request · —

AgentChoice · —

Operation result · —

No model, server, network call, arbitrary code, or extra capability runs in this browser preview. This shows the operation result, not an agent-authored final response. Run the real example · ModePot ↗