Architecture

Pytifex splits its work across two places: an LLM API for generating and refining code, and your local machine for everything that has to be objectively true — fetching GitHub issues, running the actual type checker binaries, and executing the generated code to see what happens at runtime.

The important thing to understand up front: type checker output is always real. Pytifex never asks an LLM to simulate what mypy or pyrefly would say. Every status in results.json comes from an actual subprocess call to the real binary.

Where What happens there
LLM API generating code, refining examples that didn’t diverge
Local machine GitHub mining, running mypy/pyrefly/zuban/ty, executing code to find runtime proof

Pipeline flow (pipeline.py)

Step 0 — seed mining (github_issues.py)

Pulls closed, confirmed bug-fix issues from python/mypy, facebook/pyrefly, astral-sh/ty, microsoft/pyright, and zubanls/zuban. “Confirmed” means state == "closed" and state_reason != "not_planned" — this is the actual filter, straight from github_issues.py:

def is_confirmed_bug(issue: dict) -> bool:
    if issue.get("state") != "closed":
        return False
    if issue.get("state_reason") == "not_planned":
        return False
    return True

Code gets pulled out of fenced ```python blocks, and for pyrefly specifically, out of its sandbox links too (those encode the source as base64 inside the URL).

Step 1 — code generation (prompts.py, agent.py)

3-5 seed examples get shown to the LLM with a request to generate new variations likely to cause a disagreement. If there are no seeds (--no-github, or GitHub fetch failed), it falls back to a prompt built purely from the pattern descriptions in patterns.py. This is the actual branch in pipeline.py:

if seed_examples:
    prompt = build_seed_based_prompt(batch_seeds, batch_size)
else:
    prompt = build_expert_prompt(batch_size)

agent.py has three provider backends, each a small Pydantic model with a .communicate() method:

Class Provider How it’s picked
GetAccessToCohere Cohere --model starts with command
GetAccessToOpenAI any OpenAI-compatible server --openai-base-url is set
GetAccessToGemini Google Gemini default fallback — leftover, planned for removal

Right now, provider_for_model() falls back to Gemini whenever neither of the two conditions above matches, which is why omitting --model/--openai-base-url silently uses Gemini. That default is on its way out; don’t build anything that depends on it.

GetAccessToOpenAI just hits {base_url}/chat/completions — that’s it. It works against the real OpenAI API or any local server (llama-server, Ollama, vLLM) that speaks the same protocol.

Step 2 — type checker execution (delegates to run_checkers.py)

Every generated example runs through all four checkers. If the resulting statuses aren’t all the same, it’s a disagreement and gets kept:

def has_disagreement(results: dict[str, CheckerResult]) -> bool:
    statuses = [r.status for r in results.values()]
    return len(set(statuses)) > 1

Step 3 — refinement

Examples where all four checkers agreed get sent back to the LLM along with the real checker output, with a prompt asking it to tweak the code minimally so it actually diverges. This runs up to --max-refinements times per example, feeding the latest refined attempt back in as context for the next one:

for i in range(max_attempts):
    prompt = build_refinement_prompt_for_example(current)
    response = agent.predict(prompt)
    refined = parse_into_example(response)
    refined.results = run_all_checkers(refined.code)
    if has_disagreement(refined.results):
        return refined
    current = refined  # next attempt refines this one, not the original

Step 4 — evaluation (comprehensive_eval.py)

Every surviving disagreement gets run through a two-phase evaluation that decides which checker was correct. Covered in full on the Evaluation page — short version: Phase 1 catches runtime crashes, Phase 2 uses Hypothesis + beartype to fuzz the actual functions with type-conformant inputs. (The code still names these tier1/tier2 internally — see the note at the top of the Evaluation page.)

Other evaluation code that exists but isn’t wired in

A few modules in src/pytifex/ implement additional evaluation strategies that aren’t called from the main evaluate_comprehensive() path right now — they’re either exploratory, used by other scripts, or superseded by the two-phase system:

  • source_analysis.py — pure AST analysis (no execution) that flags ~20 named PEP violations (LSP overrides, Protocol instantiation, Final overrides, TypedDict inheritance, etc.). It’s imported by comprehensive_eval.run_tier3(), but run_tier3() itself isn’t called from evaluate_comprehensive().
  • static_tier4.py — static flow analysis (import availability by Python version, variance violations, narrowing flow). Standalone, not called back into the main pipeline.
  • oracle.py — a cleaner architecture for matching source_analysis.py findings against parsed checker diagnostics.
  • checker_claim_verification.py — parses a checker’s specific diagnostic message (e.g. mypy’s Argument 1 to "f" has incompatible type "int"; expected "str"), synthesizes the exact “bad” value it’s complaining about, and calls the function with it to see if it actually crashes.
  • scoring.py — precision/recall/F1 scoring across tiers, used for writing up results rather than for the live pipeline.

If you’re trying to understand why a verdict came out a certain way, start with comprehensive_eval.py — that’s the only evaluation code that’s actually on the critical path.