agentleFS
divar-irdivar-ir/ai-doc-gen/.cursor/rules/agent-development.mdc

ai-doc-gen / rules

Cursor rule765 starsChanged 4 months agoMITView on GitHub

Guidelines for developing pydantic-ai agents, tools, and handlers

The file

We split this agent-development.mdc into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    After the run, validate_succession(files): raise ValueError only if NO output file exists.

    line 41

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
agent-development.mdc
---
description: Guidelines for developing pydantic-ai agents, tools, and handlers
globs:
  - "src/agents/**/*.py"
  - "src/handlers/**/*.py"
alwaysApply: false
---

# Agent Development

## Agent construction

Agents are built as properties on coordinator classes (`AnalyzerAgent`, `DocumenterAgent`, `AIRulesGeneratorAgent`):

```python
@property
def _structure_analyzer_agent(self) -> Agent:
    model, model_settings = self._llm_model
    return Agent(
        name="Structure Analyzer",
        model=model,
        model_settings=model_settings,
        system_prompt=self._render_prompt("agents.structure_analyzer.system_prompt"),
        tools=[FileReadTool().get_tool(), ListFilesTool().get_tool()],
        retries=config.ANALYZER_AGENT_RETRIES,
    )
```

- Model setup is OpenAI-compatible only: `OpenAIChatModel(model_name, provider=OpenAIProvider(base_url=..., api_key=..., http_client=create_retrying_client()))`. There is no Gemini/custom provider path.
- `ModelSettings`: temperature 0.0, `max_tokens`, `timeout`, `parallel_tool_calls` — all from `src/config.py` env constants.

## Prompts

- Jinja2 templates in YAML under `src/agents/prompts/` (keys like `agents.<name>.system_prompt` / `user_prompt`), loaded by `PromptManager` and rendered via `self._render_prompt(key)` with `repo_path` etc. as variables.
- New agent → new prompt section in the matching YAML file, never inline prompt strings in Python.

## Orchestration

- Analyzer: build a dict of task callables (one per non-excluded analysis), run through `WorkerPool(max_workers=self._config.max_workers)`.
- AI-rules generator: fixed pair of tasks via `asyncio.gather(*tasks, return_exceptions=True)`.
- After the run, `validate_succession(files)`: raise `ValueError` only if NO output file exists; warn on partial success listing missing files.
- Each agent writes its own output file (`.ai/docs/*.md`, README.md, CLAUDE.md/AGENTS.md, `.cursor/rules/*.mdc`); create parent dirs and clean absolute paths first.

## Tools

```python
class FileReadTool:
    def get_tool(self):
        return Tool(self._run, name="Read-File", takes_ctx=False, max_retries=...)

    def _run(self, file_path: str, line_number: int = 0, line_count: int = 200) -> str:
        """Docstring is the LLM-facing description — keep Args/Returns accurate."""
        ...
        raise ModelRetry(message="File not found")  # recoverable errors → ModelRetry
```

- Tool docstrings are what the LLM sees; keep them precise.
- Raise `ModelRetry` for recoverable failures (missing file, permission denied); set span attributes for inputs/outputs; log with `Logger.debug`.

## Handlers

- Subclass `AbstractHandler`, config = `BaseHandlerConfig` + agent config, construct the agent in `__init__`, and wrap `handle()` work in an OpenTelemetry span with `repo_path`/config-flag attributes.
- Log token usage (`result.usage().total_tokens`) and execution time after each agent run.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.