coact.policy

Completion policy — the injectable model / memory / tool choices COMPLETE stamps.

COACT_SPEC §5.4 / DECISIONS D4. The model, memory, and tool-narrowing choices are policy: injected data, not hardcoded branches, with cascading defaults in the spirit of aw.GlobalConfig (sensible defaults; override globally by constructing a different CompletionPolicy, or per-skill via the coact: block, which always wins over policy). This module imports no LLM and no aw — it is a pure mechanical path (DECISIONS D10); the aw StepConfig LLM injection used for optional persona synthesis lives behind that optional path in coact.synthesis.

The routing table is data on the dataclass, so users extend it without editing code (open-closed).

Module Attributes

default_policy

The default policy instance (importable, mutable-by-override).

Classes

CompletionPolicy([default_model, ...])

Injectable defaults for the §3.2 extras COMPLETE must stamp on a skill.

class coact.policy.CompletionPolicy(default_model='sonnet', default_memory=None, default_tools=('Read', 'Grep', 'Glob'), read_only_tools=frozenset({'Glob', 'Grep', 'NotebookRead', 'Read', 'WebFetch', 'WebSearch'}), opus_keywords=('orchestrat\\w*', 'architect\\w*', 'coordinat\\w*', '\\bplan(?:ning|s|ned)?\\b', '\\bdesign(?:s|ing|ed)?\\b', 'review\\w*'), opus_skill_threshold=3, write_keywords=('write', 'edit', 'create file', 'modify', 'generate', 'refactor'))[source]

Bases: object

Injectable defaults for the §3.2 extras COMPLETE must stamp on a skill.

>>> p = CompletionPolicy()
>>> p.choose_model(tools=['Read', 'Grep'], description='Audit the bundle.', n_skills=1)
('haiku', 'read-only/explore: tools ⊆ read-only set')
>>> p.choose_model(tools=['Read', 'Write'], description='Implement the fix.', n_skills=1)[0]
'sonnet'
>>> p.choose_model(tools=['Read'], description='Orchestrate the review.', n_skills=1)[0]
'opus'
choose_memory()[source]

The default memory scope (opt-in; None = no memory).

Return type:

tuple[Optional[Literal['user', 'project', 'local']], str]

choose_model(*, tools, description, n_skills)[source]

Route to a model from the effective tools / description / skill count.

Return type:

tuple[Literal['sonnet', 'opus', 'haiku', 'inherit'], str]

infer_tools(skill, coact_meta)[source]

Derive the tool allowlist (declared-or-heuristic + report; DECISIONS D3).

Precedence: an explicit coact: tools wins; otherwise a conservative heuristic from the skill’s resources/body. Never silently guesses — the reason is returned for provenance.

>>> from skill.base import Skill, SkillMeta
>>> s = Skill(meta=SkillMeta(name='x', description='y'), body='Write the report.')
>>> tools, why = CompletionPolicy().infer_tools(s, CoactMeta())
>>> 'Write' in tools and 'Read' in tools
True
Return type:

tuple[list[str], str]

opus_keywords: tuple[str, ...] = ('orchestrat\\w*', 'architect\\w*', 'coordinat\\w*', '\\bplan(?:ning|s|ned)?\\b', '\\bdesign(?:s|ing|ed)?\\b', 'review\\w*')

Regex patterns (matched case-insensitively against the description) that route to opus. Word-bounded so ‘plan.’ matches but ‘designer’/’designate’ don’t. Data, not code — extend or replace per policy.

override(**kwargs)[source]

Return a new policy with overridden fields (cascading defaults).

>>> CompletionPolicy().override(default_model='opus').default_model
'opus'
Return type:

CompletionPolicy

write_keywords: tuple[str, ...] = ('write', 'edit', 'create file', 'modify', 'generate', 'refactor')

body substrings that imply the agent writes/edits files.

coact.policy.default_policy = CompletionPolicy(default_model='sonnet', default_memory=None, default_tools=('Read', 'Grep', 'Glob'), read_only_tools=frozenset({'Read', 'NotebookRead', 'WebFetch', 'Grep', 'WebSearch', 'Glob'}), opus_keywords=('orchestrat\\w*', 'architect\\w*', 'coordinat\\w*', '\\bplan(?:ning|s|ned)?\\b', '\\bdesign(?:s|ing|ed)?\\b', 'review\\w*'), opus_skill_threshold=3, write_keywords=('write', 'edit', 'create file', 'modify', 'generate', 'refactor'))

The default policy instance (importable, mutable-by-override).