Capsule Corp
← Deep research case study
The recorded output

The finished PRD.

Haiku, cold: the wrong tool, denied.

Written at step 192 of 205. The text below is extracted unchanged from that run; its citations and draft caveats are the agent’s.

Download Markdown

Product Requirements Document: Decider Capsule Core

Problem

A decider component is needed to make probabilistic decisions about which verb an agent's turn should offer, selecting from options bound by the capsule. Without a decider, agents must park their runs on pending external input (contract/decide.md:111), waiting for human or external guidance before proceeding. This blocks agent autonomy and introduces latency into decision-making loops.

The decider solves this by enabling external model-based decision-making while preserving agent agency. It narrows what the reasoner sees, providing intermediate guidance (contract/decide.md:49), but maintains alternatives—the reasoner keeps backup options and can name what it needs if the decider leans wrong (contract/decide.md:35, contract/decide.md:49-50). This creates a pathway for human-in-the-loop correction without requiring the agent to halt entirely.

Current implementations like Jev select verbs using external LLMs via OpenRouter with aggressive response filtering for security, and work within capsule system constraints. However, Jev is narrowly scoped and requires substantial filtering overhead (findings from code/jev.rs analysis).

Users

Runners (who execute it):

  • The agent's reasoner, which applies the decider capability and receives its decision before deciding which verb to offer
  • The environment, which grants the decide capability via (grant capability decide/verb :kind decide) (contract/decide.md:8)

Readers (who consume its decisions):

  • The capsule's turn logic, which receives the decider's answer as an object containing form (verbs kept), distribution, provider, and version (contract/decide.md:28-30)
  • Observability and audit systems, which record the decision including question, options, and pick (contract/decide.md:37-38)
  • External decision providers (current: Jev; future: Laya), which receive state and options to score or rank
  • The reasoner, which uses the decider's ranked options but retains authority to select differently if alternatives are needed

Goals and Non-Goals

Goals

  1. Enable external probabilistic verb selection at the capsule level, allowing model-based guidance without blocking agent execution
  2. Maintain agent autonomy by keeping the reasoner's final choice authority and preserving alternatives the decider did not select (contract/decide.md:35, contract/decide.md:49-50)
  3. Handle decision failures gracefully by declining below a confidence threshold and allowing the reasoner to pick instead of parking the run (contract/decide.md:74, contract/decide.md:79)
  4. Integrate cleanly with agent turns such that both the decider crossing and the reasoner crossing happen in one turn, with costs accounted together (contract/decide.md:117)
  5. Support progressive improvements in decision quality by enabling successor providers like Laya to replace Jev with deeper task state reasoning and reduced external dependencies

Non-Goals

  1. Planning entire verb sequences (Laya may enable this, but it is not required in v1)
  2. Replacing the reasoner's authority to select the final verb
  3. Guaranteeing decision correctness; the decider's role is to provide guidance, not guarantee
  4. Removing all filtering overhead; security-sensitive response filtering will remain necessary for external model calls
  5. Eliminating external model dependencies entirely (though successor designs may reduce them)

Design

What the Decider Sees

The decider receives two inputs per decision:

  • State: The current context of the agent's turn (contract/decide.md:9)
  • Options: The list of verbs the capsule has bound as available (contract/decide.md:23-24)

Both are passed via the (offer verbs) interface (contract/decide.md:9).

What It Answers

The decider returns an object with the following fields (contract/decide.md:28-30):

  • form: The set of verbs kept after filtering, ordered by probability
  • distribution: Probabilistic scores or rankings of the kept verbs
  • provider: The name or identifier of the decision provider (e.g., "jev", "laya")
  • version: The version of the provider, enabling performance tracking and comparisons

The verbs are kept by ordering options and reaching a threshold (contract/decide.md:34).

How It Is Bound

The decider is bound as an effect capability granted by the environment:

(grant capability decide/verb :kind decide)

(contract/decide.md:8)

The binding to the agent's turn follows this sequence:

  1. The reasoner calls the decider effect with state and options
  2. The decider crosses once, returning its decision
  3. The reasoner crosses a second time to act on the decision
  4. Both crossings are atomic within a single turn (contract/decide.md:117)

The decider's cost (tokens, external calls) is accounted under the A12 budget (contract/decide.md:116), ensuring transparent cost visibility.

Without a decider configured, the run parks on the family in pending() (contract/decide.md:111), halting the turn and awaiting external input.

How It Declines

A decider declines—returning ("declined" why) instead of a decision—in the following cases (contract/decide.md:74, contract/decide.md:77, contract/decide.md:81):

  • Below threshold: Confidence falls below the configured threshold
  • Data unreadable: The state or options cannot be parsed or accessed
  • Connection lost: The external decision provider is unreachable
  • Malformed operands: The inputs do not match expected formats

When a decline occurs, the run continues with the reasoner picking a verb itself (contract/decide.md:79), rather than parking and blocking the turn. This ensures forward progress and graceful degradation.

How Laya Comes to Replace Jev

Current state (Jev): Selects verbs using an external LLM via OpenRouter. Requires aggressive response filtering for security. Works within capsule constraints but is narrowly scoped.

Successor design (Laya, proposal): Could improve the decider by:

  • Reasoning more deeply about task state rather than simple verb ranking
  • Reducing or eliminating filtering overhead through more controlled reasoning
  • Avoiding external API dependencies (potentially local or cached reasoning)
  • Providing explicit confidence metrics rather than binary threshold checks
  • Planning verb sequences rather than selecting single verbs in isolation

Replacement occurs by:

  1. Registering Laya as an alternative provider in the environment's decision provider registry
  2. The reasoner selecting Laya via provider name when granting the capability
  3. Both providers (Jev and Laya) conforming to the same effect interface: receiving state/options and returning form/distribution/provider/version
  4. The decision record tracking which provider made each choice, enabling performance comparison

Note (proposal): The router component (plan/router.md) uses calibrated classifiers for cost optimization and integrates providers as decision effects. Recent implementations moved router functionality to door.rs. The architecture supports multiple decision providers at the framework level.

Evaluation

Success Criteria

  1. Decision latency: The decider completes within SLA (proposal: <500ms for local provider, <2s for external)
  2. Verb coverage: Decider returns non-empty form in >95% of turns (no false declines)
  3. Reasoner override rate: Reasoner selects a verb not in the top decision <5% of the time (decider alignment with reasoner intent)
  4. Cost predictability: Decider cost per decision is measurable and accounts correctly to A12 budget (contract/decide.md:116)
  5. Decline handling: When decider declines, reasoner recovers to pick a verb in <100ms (no stalling)
  6. Provider comparison: Decision records track provider name and version, enabling A/B testing (contract/decide.md:28-30, contract/decide.md:37-38)

Measurement Methods

  • Latency: Log timestamp of decider entry and exit; aggregate by provider
  • Coverage: Count declines vs. total decisions; categorize decline reasons (contract/decide.md:74, contract/decide.md:77, contract/decide.md:81)
  • Alignment: Cross-reference reasoner's final pick against decider's form; track overrides
  • Cost: Audit A12 budget logs for decider call costs (contract/decide.md:116)
  • Decline recovery: Measure time from decline to reasoner's pick
  • Provider performance: Group decision records by provider and version; compare latency, coverage, and alignment (contract/decide.md:37-38)

Risks

Risk 1: External Provider Dependency

Description: Current Jev implementation depends on external LLM API (OpenRouter). Network outages, rate limits, or vendor changes could cause widespread decision declines.

Likelihood: Medium (external services have SLA impacts)

Impact: High (blocks agent turns without decider fallback to reasoner)

Mitigation: Implement robust retry logic with exponential backoff; design Laya as a local alternative that does not depend on external APIs; ensure decline → reasoner fallback is fast and reliable.

Risk 2: Security Through Filtering Overhead

Description: Jev requires aggressive response filtering to prevent prompt injection or malformed outputs. This creates latency and filtering failures could expose vulnerabilities.

Likelihood: Medium (filtering is a common attack surface)

Impact: High (security breach or malfunction)

Mitigation: Laya should reduce filtering needs through controlled reasoning; consider formal verification of response structure; implement filter tests and regular security audits.

Risk 3: Verb Selection Misalignment

Description: Decider may consistently rank verbs the reasoner disagrees with, leading to high override rates and lack of trust in the component.

Likelihood: Medium (training data mismatch or task distribution shift)

Impact: Medium (users lose confidence but reasoner fallback ensures forward progress)

Mitigation: Implement provider comparison (contract/decide.md:37-38); track override rates per provider; retrain or adjust thresholds based on alignment data.

Risk 4: Cost Explosion with External Calls

Description: If decider is called frequently and uses external APIs, token costs could exceed budget, especially if retries or fallback queries occur.

Likelihood: Medium (depends on call frequency and pricing)

Impact: Medium (affects operational budget but A12 accounting surfaces the cost)

Mitigation: Implement call rate limiting; use local caching or fast paths for common decisions; consider quota-based provider selection.

Risk 5: Decline Cascades

Description: If the decider declines frequently (e.g., due to malformed state), the reasoner picks repeatedly, potentially causing unstable or suboptimal verb sequences.

Likelihood: Low (with careful input validation)

Impact: Medium (degraded decision quality)

Mitigation: Validate state and options before calling decider; log decline reasons and alert on thresholds; implement fallback to cached recent good decisions if declines spike.

Open Questions

  1. What is the SLA for decider latency? (Proposal: <500ms local, <2s external)

    • This affects whether Laya must be synchronous or if async with reasoner fallback is acceptable.
  2. What is the minimum confidence threshold for a verb to remain in the form? (Proposal: >0.1 probability or top-N by score)

    • Current implementation uses a threshold (contract/decide.md:34); specifics are unspecified.
  3. How should multiple decision providers be selected or ranked?

    • Should the reasoner choose a provider upfront, or should there be a "provider of providers" that routes to Jev, Laya, etc. based on context?
  4. What is the expected decision failure rate, and when should we escalate to human review?

    • Contract specifies decline behavior but not operational thresholds for alerting.
  5. Should the decider support batch decisions (multiple options in one call) or only single-verb ranking?

    • Proposal: Batch support would reduce latency but may complicate provider implementations.
  6. How will Laya's training or fine-tuning be validated before production rollout?

    • What benchmarks or A/B tests are required to confirm Laya outperforms Jev?
  7. Can the decider be augmented with user feedback or expert labels to improve over time?

    • Should overrides (reasoner picks not in the decider's top form) feed a training loop?
  8. What happens if both the decider and the reasoner are unable to pick a verb?

    • Does the run still park in pending, or is there a deeper fallback?
Source in the recorded run

Document write at step 192. Its recorded content fingerprint:

sha256:46235880efc65258c72f280e01c5502889aa7407b30391d90c19983e55281829

Inspect this run and check its fingerprints →