# SereneCode: Spec, Type & Contract Verification

> Check AI-written Python against your spec, mypy types, and icontract contracts, then fix findings level by level.

SereneCode: Spec, Type & Contract Verification is a free AI agent skill on Agensi by Helgi Páll Helgason, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [Helgi Páll Helgason](https://www.agensi.io/creators/helgi-p-ll-helgason)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Uses: 3
- Version: 1.0
- Last updated: 2026-10-15
- Security: scan passed (2026-10-15); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/serenecode-spec-type-contract-verification
- Tags: ai-agents, code-review, python, static-analysis, testing, verification, type-checking, contracts

## About this skill

SereneCode turns "did the agent ship code?" into "does it match the spec, the types, and the contracts we agreed on?"

This skill teaches your agent to drive the open-source [SereneCode](https://github.com/helgster77/serenecode) verifier (MIT, on PyPI) while it writes Python:

- **Spec first.** Requirements live in `SPEC.md` as `REQ-xxx` IDs. Functions are tagged `Implements:` and tests are tagged `Verifies:`, so every requirement can be traced to code
  and tests.
- **Enforceable contracts.** Preconditions, postconditions, and class invariants with icontract. The agent writes real conditions, not tautologies.
- **Verification in the edit loop.** The agent checks each change through the SereneCode MCP tools or the CLI, at six levels:
    - L1 structure
    - L2 mypy `--strict`
    - L3 tests and coverage
    - L4 Hypothesis property testing
    - L5 CrossHair symbolic execution
    - L6 architecture
- **Fixes by level.** Each finding gives a file, line, and suggestion, and the agent fixes it and reruns the check until the verdict is complete.
- **Honest reporting.** The agent reports the overall verdict, skipped checks, and exemptions. It never claims that a passing property test proves the code correct.

**Requirements:** Python and the `serenecode` package (`pip install 'serenecode[mcp]'`). The skill asks before it installs anything, and asks before enabling code execution for
  levels 3–6. The checks come from the package; this skill is the workflow.

## Requires

- Python 3.10+
- serenecode

Install it with pip install 'serenecode[mcp]'.

## Known limitations

Requires serenecode package installation. Docstring tags must be at function/class level. Levels 4-6 require --allow-code-execution flag and user consent.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the SereneCode: Spec, Type & Contract Verification skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does SereneCode differ from a standard Python linter or type checker?

SereneCode adds a formal verification layer to Python development, using multi-level checks and requirement traceability to ensure code doesn't just run, but is mathematically and logically sound according to your SPEC.md.

### What are the technical requirements for running this skill?

The skill is designed for use with agents that support Model Context Protocol (MCP) and requires the `serenecode` Python package, along with tools like mypy, icontract, and Hypothesis, to be installed in your local environment.

### Can this skill handle both simple type checking and complex symbolic execution?

Yes, the skill manages everything from basic structural checks (L1) to advanced symbolic execution and property-based testing (L4-L6), though higher levels typically require user-granted execution permissions for safety.

### How does requirement tracing work?

Requirements live in SPEC.md as REQ-xxx IDs. Code is tagged "Implements: REQ-001" and tests "Verifies: REQ-001" in their docstrings. SereneCode reports any requirement with no implementation or no test. Tags show references exist; they don't prove the test checks the requirement's meaning.

### Is it really free?

Yes. The skill is free and the serenecode package is open source under the MIT license: https://github.com/helgster77/serenecode

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
