SKILL.md--- name: commerce-architecture description: How the reference commerce agents of either role are structured, covering the loop, where each rule lives, skills, the backend interface, delegates, and model fields. Load when designing or reviewing the structure of a shopping or merchant agent. --- # Commerce agent architecture Paths are in the reference repo: `commerce_common/` is `commerce-common/commerce_common/`, `shopping_agent/` is `shopping-agent/core/shopping_agent/`, `merchant_agent/` is `merchant-agent/core/merchant_agent/`, and the runtimes are `shopping-agent/runtime-messages-api/shopping_agent_runtime/` and `merchant-agent/runtime-messages-api/merchant_agent_runtime/`. ## One loop - One model owns the conversation. A turn is `ShoppingAgent.stream_turn` or `MerchantAgent.stream_turn` (each runtime's `orchestrator.py`): the model reads the cached prompt, calls tools (one round's calls run concurrently), and ends with text plus presentation calls. There is no router, classifier, or hand-off. - Every call on every path runs through the role executor (`ShoppingToolExecutor` in `shopping_agent/executor.py`, `MerchantToolExecutor` in `merchant_agent/executor.py`) over `BaseToolExecutor` in `commerce_common/execution.py`. The Messages API runtime, the Agent SDK toolset, and the MCP server call the same `execute`, which never raises; after `max_tool_iterations` rounds (`commerce_common/config.py`) the runtime forces a round without tools. ## Where a rule lives | A rule that applies | Lives in | Reference | |---|---|---| | While one call's arguments are being filled in | That tool's description | `build_tools` in each role's `tools/registry.py` | | On most turns: cart and checkout, the staged-write contract, presentation grammar, tool order, trust rules | The static prompt | `build_static_system` in each role's `prompt.py` | | On the minority of requests that need a multi-step procedure | A skill, loaded on demand | `shopping-agent/skills/`, `merchant-agent/skills/` | A rule the core journey needs on most conversations moves a layer down. This table is the one statement of the layering. ## Skills - A skill is a directory holding `SKILL.md`: frontmatter `name` and `description`, then the body (`parse_skill_md` in `commerce_common/skills.py`). The description names the request class; it carries no sample utterances. - The static prompt carries the index alone (`SkillRegistry.index_block`, sorted by name) and `load_skill` returns one body (`_load_skill` in `commerce_common/execution.py`). On the Agent SDK, `ensure_project_skills` links the same directories into `.claude/skills/` and `SKILL_TOOL_ADAPTER` points the model at the SDK's `Skill` tool (`commerce_common/agent_sdk.py`); the hosted manifests list the directories under `skills[]` in `agent.yaml`. ## The backend interface A deployment implements one abstract class per role; nothing else reaches i