AI Agent Development Protocol for the ProFiT Framework
Defines mandatory rules for an AI agent writing Python code for the ProFiT framework, covering tooling, testing, typing, and documentation.
What this file does
Defines mandatory rules for an AI agent writing Python code for the ProFiT framework, covering tooling, testing, typing, and documentation.
When to use it
- You want to enforce consistent coding standards across an AI-assisted project
- You need a strict protocol for an AI agent generating production code
- You are setting up a new Python project with uv, pytest, mypy, and ruff
- You require 100% test coverage and Google-style docstrings
Assumes this stack
AI Agent Development Protocol for the ProFiT Framework
1. Mission Statement
This document outlines the strict, non-negotiable rules and development protocol for the AI agent responsible for writing the source code of the ProFiT framework. The agent's primary directive is to produce code that is robust, maintainable, testable, and perfectly aligned with the technical specification. Adherence to this protocol is mandatory for every code generation task.
2. Core Mandates
Rule #1: Python Language Exclusivity
The Agent MUST write all application and test code in Python 3.11 or newer. No other programming languages are permitted.
Rule #2: Environment and Dependency Management (uv Only)
The Agent MUST use uv exclusively for all environment and dependency management tasks.
- Forbidden Tools:
pip,venv,virtualenv,poetry,pipenv, or any other package manager are strictly forbidden. The only exception is the initial bootstrap installation ofuvitself. - Creating Environments: A virtual environment must be created with
uv venv. - Activating Environments: The environment must be activated with
source .venv/bin/activate(for Unix-like systems). - Managing Dependencies:
- To add a new dependency:
uv pip install <package_name> - To install all dependencies for the project:
uv pip sync requirements.txt - After adding a new dependency, the
requirements.txtfile MUST be updated with:uv pip freeze > requirements.txt
- To add a new dependency:
Rule #3: Rigorous and Comprehensive Testing
Code without tests is considered broken.
- Test Framework: The Agent MUST use the
pytestframework for all unit and integration tests. - Test-Driven Mindset: For any new function or class, the test file MUST be created first or concurrently. The agent should follow a "Red-Green-Refactor" thought process.
- Test Location: All test files must reside in the
/testsdirectory and mirror the source code's directory structure. For example, the tests forprofit/core/optimizer.pyMUST be located attests/core/test_optimizer.py. - Coverage: Code generation is not complete until the new code is covered by tests. The goal is to maintain 100% test coverage.
Rule #4: Comprehensive Documentation via Docstrings
Every functional component MUST be documented.
- Docstring Format: The Agent MUST write docstrings for every module, class, method, and function using the Google Style Python Docstrings format.
- Content: Docstrings must include a one-line summary, a more detailed description,
Args:for all parameters with their types, and aReturns:section describing the output and its type.
Rule #5: Robust and Explicit Static Typing
Code must be clear about the data it handles.
- Type Hinting: The Agent MUST use Python's
typingmodule extensively for all function signatures, variables, and class attributes. - No
Any: The use oftyping.Anyis strictly forbidden. The Agent must always endeavor to use more specific types, such aslist[str],dict[str, float],Callable[[int], str], or customTypeDictandNewTypedefinitions. If a generic type is absolutely necessary,objectis preferred overAny.
3. Development Workflow Example
This is the standard operating procedure for adding a new function, calculate_sharpe_ratio, to a metrics.py module.
-
Define the Interface (Code and Test):
- Create the file
profit/analyzer/metrics.py. - Write the function signature with types and a complete docstring first:
# profit/analyzer/metrics.py from typing import List def calculate_sharpe_ratio(returns: List[float], risk_free_rate: float) -> float: """Calculates the annualized Sharpe ratio from a list of returns. Args: returns (List[float]): A list of periodic returns (e.g., daily). risk_free_rate (float): The annualized risk-free rate. Returns: float: The calculated annualized Sharpe ratio. """ # Implementation to be added pass - Create the test file
tests/analyzer/test_metrics.py. - Write a test case that will initially fail:
# tests/analyzer/test_metrics.py from profit.analyzer import metrics import pytest def test_calculate_sharpe_ratio(): """Tests the Sharpe ratio calculation with a sample case.""" # This test will fail until the function is implemented sample_returns = [0.01, -0.005, 0.02, 0.015] risk_free = 0.02 # The expected value needs to be pre-calculated expected_sharpe = 1.234 # Placeholder assert metrics.calculate_sharpe_ratio(sample_returns, risk_free) == pytest.approx(expected_sharpe)
- Create the file
-
Implement the Functionality:
- Write the business logic inside the
calculate_sharpe_ratiofunction until the testtest_calculate_sharpe_ratiopasses.
- Write the business logic inside the
-
Refactor and Add Edge Case Tests:
- Add more tests to
test_metrics.pycovering edge cases: empty returns list, all zero returns, etc. Ensure they raise appropriate exceptions or return expected values (e.g., 0.0). - Refactor the implementation for clarity and performance if needed.
- Add more tests to
-
Final Verification:
- Before concluding the task, run the full verification suite from the project root:
# 1. Run all tests uv run pytest # 2. Run the static type checker uv run mypy . # 3. Run the linter uv run ruff check . - Only if all three commands pass without error is the task considered complete.
- Before concluding the task, run the full verification suite from the project root:
The Agent's performance will be judged on its strict adherence to this protocol.
What's inside
5 core mandates, 1 workflow example with 4 steps and 3 verification commands, 2 code snippets
Change this for your project
- Replace
ProFiTandprofitwith your own project name and package name - Replace
JulesLscx/ProFiTwith your own repository URL - Replace
profit/analyzer/metrics.pyandprofit/core/optimizer.pywith your own module paths
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Requiring test files to mirror source directory structure under /tests
- Using a Red-Green-Refactor workflow with interface-first definition
- Forbidding
typing.Anyand preferring specific types orobject
Related Documents
Totem — Development Rules
Defines team-wide conventions for a pnpm monorepo: branch strategy, commit rules, tooling, and a mandatory knowledge-search workflow before coding.
MechCAD-MLLM
Proposes a MLLM + dual-decoder architecture for mechanical CAD generation, combining Drawing2CAD and CAD-GPT ideas.
Prompt Generator
Generates Stable Diffusion and Flux prompts via Qwen3-8B on Ollama, with a Gradio UI and CLI.
Agent Instructions
Defines a three-layer architecture (directive, orchestration, execution) for AI agents that self-anneal errors and update living SOPs.