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.
- 01Request fixes the ID
FromRequest - 02Choice stays within two formats
AgentChoice - 03Application runs one lookup
Exactly(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 PREVIEWThe operation result will appear here.
- Customer ID
- —
- Customer
- —
- Status
- —
- Chosen format
- —
Inspect the bound arguments
- Validate request
- Bound format choice
- Required lookup × 1
- 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 ↗