# ReasonBlocks ## Docs - [CodebaseMemory class reference](https://docs.reasonblocks.com/api-reference/codebase-memory.md): API reference for CodebaseMemory — store, recall, invalidate, and manage per-codebase agent findings with semantic search and cache coverage helpers. - [ImportGraph class reference](https://docs.reasonblocks.com/api-reference/import-graph.md): API reference for ImportGraph — build Python import graphs and query the blast radius of changed files to drive targeted cache invalidation. - [Anthropic and Claude Agent SDK tool factories](https://docs.reasonblocks.com/api-reference/integrations/claude-tools.md): make_claude_tools() for the Anthropic Messages API and make_claude_agent_sdk_tools() for the Claude Agent SDK, both wiring CodebaseMemory and ImportGraph. - [LangChain tool factories](https://docs.reasonblocks.com/api-reference/integrations/langchain-tools.md): make_langchain_tools() returns LangChain @tool callables for CodebaseMemory recall, finding storage, and import-graph impact analysis. - [OpenAI Agents SDK tool factories](https://docs.reasonblocks.com/api-reference/integrations/openai-tools.md): make_openai_tools() returns function_tool callables for the openai-agents SDK, wiring CodebaseMemory recall, finding storage, and import-graph impact analysis. - [ReasonBlocks class reference](https://docs.reasonblocks.com/api-reference/reasonblocks.md): API reference for the ReasonBlocks class — constructor options, middleware(), openai_hooks(), and the score_step() heuristic scorer. - [Custom harness quickstart](https://docs.reasonblocks.com/api-reference/rest-api/custom-harness-quickstart.md): Wire ReasonBlocks into your own agent loop or evaluation runner with three HTTP calls — no SDK required. Works with any language. - [REST API overview](https://docs.reasonblocks.com/api-reference/rest-api/overview.md): Call ReasonBlocks directly over HTTP from a custom harness — no SDK required. Use this when your agent loop isn't on a supported framework, or when you want a thin language-agnostic integration. - [REST API setup](https://docs.reasonblocks.com/api-reference/rest-api/setup.md): Base URL, authentication, environment variables for self-hosting, rate limits, CORS, and error codes for the ReasonBlocks REST API. - [Versioning & back-compat](https://docs.reasonblocks.com/api-reference/rest-api/versioning.md): What the /v1/ contract guarantees, how breaking changes ship, and how legacy unversioned aliases work for already-deployed SDK clients. - [SteeringSession](https://docs.reasonblocks.com/api-reference/steering-session.md): Framework-agnostic steering pipeline. Drives FSM scoring, monitor evaluation, E-trace retrieval, and live telemetry for the Claude Messages and OpenAI Agents integrations. - [TokenSavingMiddleware reference](https://docs.reasonblocks.com/api-reference/token-saving-middleware.md): API reference for TokenSavingMiddleware — compress old tool outputs, trigger early exit when agents loop, and track token savings with stats. - [ETrace: retrieved steering pattern](https://docs.reasonblocks.com/api-reference/types/e-trace.md): Reference for the ETrace dataclass — the raw shape of patterns the SDK retrieves from rb-api before rendering them into system-prompt injections. - [FSMState: agent difficulty state enum](https://docs.reasonblocks.com/api-reference/types/fsm-state.md): Reference for the FSMState enum — the six states ReasonBlocks uses to classify per-step difficulty and trigger model routing, monitor injection cooldowns, and E-trace gating. - [StepRecord, TraceState, and StepLogEntry](https://docs.reasonblocks.com/api-reference/types/step-record.md): Reference for the per-step dataclasses ReasonBlocks records during a run — StepRecord and TraceState in reasonblocks.types, and StepLogEntry on the middleware. - [E-traces](https://docs.reasonblocks.com/concepts/e-traces.md): The three tiers of steering injection — E1 instance-level, E2 failure-mode patterns, E3 universal rules — how each tier is gated, and how their text reaches the system message. - [FSM states](https://docs.reasonblocks.com/concepts/fsm-states.md): How the difficulty FSM classifies agent trajectories across INIT, FAST, NORMAL, SLOW, SKIP, and END, and how each state controls E-trace retrieval, monitor cooldowns, and model routing. - [How it works](https://docs.reasonblocks.com/concepts/how-it-works.md): The middleware lifecycle: run_start, before_model scoring and FSM transition, server-side monitor evaluation, E-trace gating, model routing, system-message rendering, and run_finish. - [Monitors](https://docs.reasonblocks.com/concepts/monitors.md): ReasonBlocks runs six trajectory monitors server-side on /monitors/evaluate. They detect failure patterns mid-run and produce the steering text appended to the system message. - [Advanced configuration](https://docs.reasonblocks.com/configuration/advanced.md): Lower-level knobs: FSM thresholds, model routing, live streaming, token-budget tracking, stage-timing instrumentation, and run metadata. - [Monitor weights and profiles](https://docs.reasonblocks.com/configuration/monitor-profiles.md): The six server-side trajectory monitors, the built-in task profiles (coding, pr_review, qa) that weight them, and how to override weights per call. - [ReasonBlocksConfig: full configuration reference](https://docs.reasonblocks.com/configuration/reasonblocks-config.md): Reference for the ReasonBlocksConfig dataclass and build_middleware factory — an alternate path to assembling the middleware stack from a single dataclass. - [Run an A/B evaluation](https://docs.reasonblocks.com/guides/ab-testing.md): Randomly route each agent run to ReasonBlocks ON (full pipeline) or OFF (vanilla), then pull a per-arm report comparing cost, token usage, and task accuracy. Built for proving value during an evaluation. - [Chain-of-Draft reasoning style](https://docs.reasonblocks.com/guides/chain-of-draft.md): Replace verbose Chain-of-Thought with minimalist ≤5-word drafts. Prompt-only, zero infra, composes with any setup. - [Claude Agent SDK](https://docs.reasonblocks.com/guides/claude-agent-sdk.md): Wire ReasonBlocks codebase memory tools into a Claude Agent SDK / Claude Code agent loop. - [Use ReasonBlocks with the Anthropic Messages API](https://docs.reasonblocks.com/guides/claude-messages.md): Drive run_messages_agent_loop with a SteeringSession to run the full FSM + monitor + E-trace + model-routing pipeline against Claude Messages. - [Token reduction for coding agents](https://docs.reasonblocks.com/guides/code-review-mode.md): The middleware stack measured at -51.8% input tokens at unchanged pass rate on n=75 paired SWE-bench Pro runs, assembled from TokenSavingMiddleware and the general monitor. - [Persist agent findings with CodebaseMemory](https://docs.reasonblocks.com/guides/codebase-memory.md): Store, recall, and invalidate per-codebase findings using CodebaseMemory — a transport-resilient client for the ReasonBlocks findings store. - [Use ReasonBlocks with LangChain](https://docs.reasonblocks.com/guides/langchain.md): Add ReasonBlocksMiddleware to LangChain or LangGraph agents for FSM scoring, monitor steering, E-trace injection, and per-step telemetry. - [Use ReasonBlocks with LangGraph](https://docs.reasonblocks.com/guides/langgraph.md): Two integration shapes: rb.middleware() for create_agent-based LangGraph apps, SteeringSession for hand-rolled StateGraphs. - [Route models by FSM state](https://docs.reasonblocks.com/guides/model-routing.md): Map FSM states to model identifiers so easy steps run on a cheap model and hard steps escalate. Routing is keyed on the live FSM state inside wrap_model_call. - [Use ReasonBlocks with OpenAI Agents](https://docs.reasonblocks.com/guides/openai-agents.md): Two integration shapes: rb.openai_model wraps a Model with the full steering pipeline, rb.openai_hooks emits telemetry only. Plus codebase memory tools. - [PR-review trajectory cache](https://docs.reasonblocks.com/guides/pr-review-etrace.md): Cache successful PR reviews and inject them as prescriptive hints on similar new PRs. Cuts the number of LLM calls per review rather than the cost per call. Provider-agnostic — works on any model that follows instructions. - [Prompt caching](https://docs.reasonblocks.com/guides/prompt-caching.md): Prompt caching is the highest-ROI token lever and costs nothing to enable. Verify cache_control markers fire, never compress before caching, and watch the hit rate climb. - [Reduce token usage with TokenSavingMiddleware](https://docs.reasonblocks.com/guides/token-saving.md): Compress stale tool outputs, nudge stuck agents to exit, and optionally apply LLM word-level compression on stale messages — all in a standalone AgentMiddleware. - [Installation](https://docs.reasonblocks.com/installation.md): Install the ReasonBlocks SDK from PyPI and configure the client. Covers every constructor parameter, environment variables, and self-hosted deployments. - [What is ReasonBlocks?](https://docs.reasonblocks.com/introduction.md): A drop-in SDK that makes production AI agents observable, self-correcting, and cheaper to run — and lets you prove the impact with built-in A/B reporting. Works with LangChain, LangGraph, the OpenAI Agents SDK, and Claude. - [Quickstart](https://docs.reasonblocks.com/quickstart.md): Install the SDK, create a ReasonBlocks client, and add the middleware to a LangChain agent. - [Troubleshoot common ReasonBlocks issues](https://docs.reasonblocks.com/troubleshooting/common-issues.md): Diagnose and fix the issues users hit most: import errors, missing injections, FAST-mode never triggering, over-injection, TokenSaving not compressing, and stuck dashboard rows. - [Frequently asked questions](https://docs.reasonblocks.com/troubleshooting/faq.md): Answers to common questions about ReasonBlocks setup, debugging traces, FSM behavior, middleware ordering, run tagging, and stuck dashboard rows.