# coact.synthesis

Persona & return-contract synthesis — the two real “extras” of a skill→agent lift.

COACT_SPEC §5.5 / §3.2. A skill body is *procedural*, not a persona, and skills
return *nothing*. The two fields that actually turn a skill into an agent are the
**system prompt (persona/identity)** and the \*\*return contract (consumable
output)\*\*. This module synthesizes both.

This PR ships the **template** path (no LLM, always available, a sound default).
The optional **LLM-assisted** path (a richer persona drafted from the skill body
via an injected facade) is added on top in a later milestone — both paths obey
the same rules: author-pinned `coact: persona` / `coact: returns` always win
(inspectable, overridable, LLM-assisted-but-not-required, DECISIONS D10).

Crucially the persona **references** the skill by name and instructs the agent to
follow it — it never copies the skill body (point-don’t-copy / SSOT, §3.3).

### Module Attributes

| [`DEFAULT_RETURN_SCHEMA`](#coact.synthesis.DEFAULT_RETURN_SCHEMA)   | A generic-but-useful default return schema (used when the author pins none).   |
|--------------------------------------------------------------------------|--------------------------------------------------------------------------------|

### Functions

| [`render_return_contract_section`](#coact.synthesis.render_return_contract_section)(rc)                | Render the human/model-facing "Return contract" markdown for a persona body.   |
|----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [`synthesize_persona`](#coact.synthesis.synthesize_persona)(skill, \*, return_contract)    | Synthesize the system prompt (persona) for an agent derived from `skill`.      |
| [`synthesize_return_contract`](#coact.synthesis.synthesize_return_contract)(skill, \*, coact_meta) | Choose the agent's return contract: author-pinned, else a template default.    |

### coact.synthesis.DEFAULT_RETURN_SCHEMA *= {'properties': {'result': {'description': 'The primary artifact or finding.'}, 'status': {'enum': ['ok', 'partial', 'failed'], 'type': 'string'}, 'summary': {'description': 'One-paragraph summary of what was done.', 'type': 'string'}}, 'required': ['summary', 'status'], 'type': 'object'}*

A generic-but-useful default return schema (used when the author pins none).

### coact.synthesis.render_return_contract_section(rc)

Render the human/model-facing “Return contract” markdown for a persona body.

```pycon
>>> rc = ReturnContract(json_schema={'type': 'object'}, description='findings')
>>> 'Return contract' in render_return_contract_section(rc)
True
```

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### coact.synthesis.synthesize_persona(skill, , return_contract, tools=None, extra_skills=None, llm=None)

Synthesize the system prompt (persona) for an agent derived from `skill`.

Wraps the skill’s intent as an identity, states operating invariants, and
appends the return contract — while **pointing at** the source skill rather
than inlining it (§3.3). The identity paragraph is template-generated by
default; when an `llm` is resolvable it is *drafted* by the LLM instead
(richer, but the invariants and the return contract stay deterministic so the
machine-facing contract is never at the mercy of generation). The LLM is
optional — absent one, the template path is a sound default (DECISIONS D10).

```pycon
>>> from skill.base import Skill, SkillMeta
>>> s = Skill(meta=SkillMeta(name='ux-analyst', description='Analyze UX bundles.'), body='steps')
>>> rc = ReturnContract(json_schema={'type': 'object'}, description='findings')
>>> persona, src = synthesize_persona(s, return_contract=rc, tools=['Read', 'Grep'])
>>> 'ux-analyst' in persona and 'Return contract' in persona and src == 'synthesized-template'
True
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'skill'`, `'coact-frontmatter'`, `'policy'`, `'inferred'`, `'synthesized-template'`, `'synthesized-llm'`, `'default'`]]

### coact.synthesis.synthesize_return_contract(skill, , coact_meta)

Choose the agent’s return contract: author-pinned, else a template default.

```pycon
>>> from skill.base import Skill, SkillMeta
>>> s = Skill(meta=SkillMeta(name='x', description='y'), body='z')
>>> rc, src = synthesize_return_contract(s, coact_meta=CoactMeta())
>>> rc.json_schema['type'], src
('object', 'synthesized-template')
>>> rc2, src2 = synthesize_return_contract(s, coact_meta=CoactMeta(returns={'schema_ref': 'm:N'}))
>>> rc2.ref, src2
('m:N', 'coact-frontmatter')
```

* **Return type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`ReturnContract`](coact.base.html.md#coact.base.ReturnContract), [`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'skill'`, `'coact-frontmatter'`, `'policy'`, `'inferred'`, `'synthesized-template'`, `'synthesized-llm'`, `'default'`]]
