Metadata-Version: 2.4
Name: requisite-ai
Version: 0.42.0
Summary: A provider-agnostic, plugin-based framework for building AI applications and agents. Declare what you need -- providers, tools, capabilities -- not which SDK provides it.
License: MIT
Project-URL: Homepage, https://github.com/requisite-ai/requisite-ai
Project-URL: Repository, https://github.com/requisite-ai/requisite-ai
Keywords: ai,agents,llm,openai,gemini,ollama,agentic,orchestration,mcp,rag
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.7
Requires-Dist: pydantic-settings>=2.3
Provides-Extra: openai
Requires-Dist: openai>=1.35; extra == "openai"
Provides-Extra: gemini
Requires-Dist: google-genai>=1.0; extra == "gemini"
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.116; extra == "anthropic"
Provides-Extra: groq
Requires-Dist: openai>=1.35; extra == "groq"
Provides-Extra: azure-openai
Requires-Dist: openai>=1.35; extra == "azure-openai"
Provides-Extra: openrouter
Requires-Dist: openai>=1.35; extra == "openrouter"
Provides-Extra: together
Requires-Dist: openai>=1.35; extra == "together"
Provides-Extra: ollama
Requires-Dist: ollama>=0.6; extra == "ollama"
Provides-Extra: langgraph
Requires-Dist: langgraph>=1.0; extra == "langgraph"
Provides-Extra: mcp
Requires-Dist: mcp<3.0,>=2.0; extra == "mcp"
Provides-Extra: pinecone
Requires-Dist: pinecone>=9.0; extra == "pinecone"
Provides-Extra: weaviate
Requires-Dist: weaviate-client>=4.0; extra == "weaviate"
Provides-Extra: rag
Requires-Dist: openai>=1.35; extra == "rag"
Requires-Dist: google-genai>=1.0; extra == "rag"
Provides-Extra: redis
Requires-Dist: redis>=5.0; extra == "redis"
Provides-Extra: otel
Requires-Dist: opentelemetry-api>=1.20; extra == "otel"
Provides-Extra: crewai
Requires-Dist: crewai>=1.15; extra == "crewai"
Provides-Extra: autogen
Requires-Dist: autogen-agentchat>=0.7; extra == "autogen"
Requires-Dist: autogen-core>=0.7; extra == "autogen"
Provides-Extra: adk
Requires-Dist: google-adk>=2.11; extra == "adk"
Provides-Extra: openai-agents
Requires-Dist: openai-agents>=0.23; extra == "openai-agents"
Provides-Extra: strands
Requires-Dist: strands-agents>=1.57; extra == "strands"
Provides-Extra: agent-framework
Requires-Dist: agent-framework-core>=1.20; extra == "agent-framework"
Provides-Extra: all
Requires-Dist: openai>=1.35; extra == "all"
Requires-Dist: google-genai>=1.0; extra == "all"
Requires-Dist: anthropic>=0.116; extra == "all"
Requires-Dist: ollama>=0.6; extra == "all"
Requires-Dist: langgraph>=1.0; extra == "all"
Requires-Dist: mcp<3.0,>=2.0; extra == "all"
Requires-Dist: pinecone>=9.0; extra == "all"
Requires-Dist: weaviate-client>=4.0; extra == "all"
Requires-Dist: redis>=5.0; extra == "all"
Requires-Dist: opentelemetry-api>=1.20; extra == "all"
Requires-Dist: autogen-agentchat>=0.7; extra == "all"
Requires-Dist: autogen-core>=0.7; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: ruff==0.14.14; extra == "dev"
Requires-Dist: mypy==2.3.0; extra == "dev"
Requires-Dist: opentelemetry-sdk>=1.20; extra == "dev"
Dynamic: license-file

# Requisite

[![CI](https://github.com/requisite-ai/requisite-ai/actions/workflows/ci.yml/badge.svg)](https://github.com/requisite-ai/requisite-ai/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/requisite-ai/requisite-ai/branch/main/graph/badge.svg)](https://codecov.io/gh/requisite-ai/requisite-ai)
[![PyPI](https://img.shields.io/pypi/v/requisite-ai.svg)](https://pypi.org/project/requisite-ai/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)

**Declare what your AI application needs — not which SDK provides it.**

A provider-agnostic, plugin-based Python framework for building AI
applications and agents. Swap the LLM provider, the multi-agent execution
engine, or the implementation behind a capability like `"weather"` or
`"internet_search"` — all via configuration, never a rewrite.

```python
from requisite import AI

ai = AI()  # provider="openai" by default
ai = AI(provider="anthropic", model="claude-sonnet-4-6")  # same API, different provider
ai = AI(provider="gemini", model="gemini-2.5-flash")
ai = AI(provider="groq", model="llama-3.3-70b-versatile")
```

```python
from requisite import Agent

agent = Agent(name="Assistant", provider="openai")
agent.requires("weather", "internet_search", "filesystem")  # not use_tool(specific_impl)
agent.run("What's the weather in Tokyo?")
```

## Install

Requisite is [published on PyPI](https://pypi.org/project/requisite-ai/):

```bash
pip install requisite-ai                  # core only -- no provider SDKs
pip install "requisite-ai[all]"           # every provider + langgraph
pip install "requisite-ai[openai]"        # OpenAI only
pip install "requisite-ai[anthropic]"     # Anthropic (Claude) only
pip install "requisite-ai[gemini]"        # Gemini only
pip install "requisite-ai[groq]"          # Groq only (uses the openai package -- wire-compatible)
pip install "requisite-ai[azure_openai]"  # Azure OpenAI only (uses the openai package)
pip install "requisite-ai[mcp]"           # MCP client + server integration
pip install "requisite-ai[rag]"           # RAG (embedding providers; in-memory vector store needs nothing extra)
pip install "requisite-ai[langgraph]"     # native + langgraph orchestration
pip install "requisite-ai[crewai]"        # native + CrewAI orchestration (sequential only)
pip install "requisite-ai[autogen]"       # native + AutoGen orchestration (sequential + supervisor)
pip install "requisite-ai[adk]"           # native + Google ADK orchestration (sequential + supervisor)
pip install "requisite-ai[openai_agents]" # native + OpenAI Agents SDK orchestration (sequential + supervisor)
pip install "requisite-ai[strands]"       # native + AWS Strands Agents orchestration (sequential + supervisor)
pip install "requisite-ai[agent_framework]"  # native + Microsoft Agent Framework orchestration (sequential + supervisor)
```

> Quoting the package name (`"requisite-ai[all]"`) avoids shell globbing
> issues with `[...]` in zsh; plain `pip install requisite-ai[all]` also
> works in bash.

**Contributing to Requisite itself** (not just using it)? See
[`CONTRIBUTING.md`](CONTRIBUTING.md) for an editable install from source
(`pip install -e ".[dev,all]"`) and running the test suite/linters.

> **Note on the Gemini SDK:** this framework uses the current, unified
> `google-genai` package (`from google import genai`). Do not install the
> deprecated `google-generativeai` package — the two conflict.
>
> **Note on Azure OpenAI:** uses Azure's current **v1 GA API** (the plain
> `openai` client pointed at your endpoint) — no separate SDK, no dated
> `api-version` string. See [ADR-0002](docs/adr/0002-provider-kwargs-and-memory-integration.md).
>
> **Note on `crewai` + MCP:** `crewai` (verified at 1.15.17) hard-pins
> `mcp~=1.28.1`, which conflicts with this project's own `mcp>=2.0,<3.0`
> ([ADR-0025](docs/adr/0025-mcp-2x-migration.md)). Installing both in
> the same environment can let pip's resolver silently downgrade `mcp`
> below 2.0, breaking any MCP client/server code with errors like
> `'Tool' object has no attribute 'input_schema'`. That's why `crewai`
> is deliberately **not** included in `requisite-ai[all]` — if you need
> both the `crewai` orchestrator backend and MCP in the same project,
> install `requisite-ai[crewai]` first, then re-assert
> `pip install "mcp>=2.0,<3.0"` afterward (and again any time you
> reinstall/upgrade `crewai`), or keep them in separate environments.
> See [ADR-0027](docs/adr/0027-crewai-autogen-orchestrator-backends.md).
>
> **Note on `google-adk`'s install weight:** unlike every other optional
> backend, `google-adk`'s *base* install (no extras) pulls in `fastapi`,
> `uvicorn`, `starlette`, `watchdog`, and `graphviz` — its `adk web`/
> `adk eval`/deploy CLI tooling ships in the core package, not behind
> extras. It also bumps `google-genai` to `>=2.19` (our own `gemini`
> extra pins no upper bound, so this is upgrade pressure, not a hard
> conflict). `requisite-ai[adk]` is a materially heavier install than
> `langgraph`/`crewai`/`autogen` — see
> [ADR-0039](docs/adr/0039-adk-orchestrator-backend.md).

## Configuration

Copy `.env.example` to `.env` and fill in the key(s) for the provider(s) you use:

```env
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GEMINI_API_KEY=
GROQ_API_KEY=
AZURE_OPENAI_API_KEY=
AZURE_OPENAI_ENDPOINT=
DEFAULT_PROVIDER=openai
MODEL=gpt-4o-mini
TEMPERATURE=0.2
RATE_LIMIT_RPM=          # optional -- see "Rate limiting" below
```

`Settings` (`requisite/config/settings.py`) reads this automatically — you
never call `os.environ.get` yourself. `.env.example` also reserves
placeholders for planned integrations (GitHub, Hugging Face, AWS, Azure
general-purpose credentials, Pinecone, Weaviate) — see `ROADMAP.md`.

## CLI

Get from `pip install` to a running agent without writing any Python:

```bash
requisite init my-app --provider gemini
cd my-app
pip install -r requirements.txt
cp .env.example .env   # then fill in your Gemini API key
python main.py
```

`requisite init` scaffolds a runnable project, including an `agents.py`
with an example `Agent` registered on a module-level `agent_registry` —
the convention the rest of the CLI looks for:

```bash
requisite providers        # every registered provider -- SDK installed? API key set?
requisite capabilities     # every registered capability and its competing providers
requisite agents           # agents registered in this project's agents.py
requisite plugins          # installed packages registered under the "requisite.plugins" entry-point group
requisite chat             # interactive chat REPL (bare AI, or --agent NAME for a project agent)
requisite chat "explain LangGraph in one sentence"   # one-shot
```

Also runnable as `python -m requisite`. See
[ADR-0014](docs/adr/0014-cli.md) for why "list registered agents" needed
a project convention rather than a new global registry, and why the CLI
prints directly to stdout instead of going through `logging` like the
rest of the framework.

## Usage

### Chat

```python
from requisite import AI

ai = AI()
print(ai.chat("Explain LangGraph in one sentence."))
```

### Supported providers

| Provider | `provider=` | Model examples | Notes |
|---|---|---|---|
| OpenAI | `"openai"` | `gpt-4o-mini`, `gpt-4o` | |
| Anthropic | `"anthropic"` | `claude-sonnet-4-6`, `claude-opus-4-8` | Native structured output via `messages.parse` |
| Gemini | `"gemini"` | `gemini-2.5-flash`, `gemini-2.5-pro` | Uses the unified `google-genai` SDK |
| Groq | `"groq"` | `llama-3.3-70b-versatile`, `openai/gpt-oss-20b` | OpenAI-wire-compatible; uses the `openai` package |
| Azure OpenAI | `"azure_openai"` | your deployment name | Requires `azure_endpoint` (or `AZURE_OPENAI_ENDPOINT`); current v1 GA API, no `api-version` needed |
| OpenRouter | `"openrouter"` | `openai/gpt-4o-mini`, `anthropic/claude-sonnet-4-6` | OpenAI-wire-compatible; routes to many underlying providers |
| Together AI | `"together"` | `meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8` | OpenAI-wire-compatible; hosts open-source models |
| Ollama | `"ollama"` | `llama3.2`, `qwen3` | Local (or remote) models; uses the native `ollama` client, not an OpenAI-compat shim |

Switching between any of these is the `provider=`/`AZURE_OPENAI_ENDPOINT`
change shown above — no other code changes. See
[ADR-0002](docs/adr/0002-provider-kwargs-and-memory-integration.md) for
why Groq, Azure OpenAI, OpenRouter, and Together AI are implemented as
thin `OpenAIProvider` subclasses rather than separate SDKs.

### Structured output

```python
from pydantic import BaseModel

class Person(BaseModel):
    name: str
    age: int

person = ai.chat("Extract: John is 30 years old.", response_model=Person)
print(person.name, person.age)  # John 30
```

### Tool calling

```python
from requisite.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 22C in {city}"

response = ai.chat_response("What's the weather in Paris?", tools=[get_weather])
if response.has_tool_calls:
    call = response.tool_calls[0]
    result = get_weather.tool.execute(**call.arguments)
```

That's the low-level view. For most applications, let an `Agent` run the
full tool-calling loop for you (see below).

### Agents

```python
from requisite import Agent
from requisite.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 22C in {city}"

agent = Agent(name="Weather Agent", provider="openai", tools=[get_weather])
result = agent.run("What's the weather in Paris?")
print(result.content)              # "It's sunny and 22C in Paris."
print(result.tool_calls_executed)  # ["get_weather"]
```

`Agent` automatically: offers its tools/skills to the model, executes any
tool calls the model requests, feeds results back, and repeats (up to
`max_iterations`) until it has a final answer.

### Request-scoped context: who is this run for?

Serving many users at once? Pass a `RequestContext` to `run()` / `arun()` (on
an `Agent` or a `Workflow`) and every tool and provider call in that run can
read it, so concurrent requests for different users stay isolated:

```python
from requisite import Agent, RequestContext, tool

@tool
def close_ticket(ctx: RequestContext, ticket_id: str) -> str:   # ctx is hidden from the model
    """Close a support ticket."""
    audit.record(operator=ctx.user, tenant=ctx.tenant, ticket=ticket_id)
    return "closed"

agent = Agent(name="resolver", provider="gemini", tools=[close_ticket])
agent.run("Close ticket T-100",
          context=RequestContext(user="alice", tenant="acme", correlation_id="req-7"))
```

- A tool parameter annotated `RequestContext` (or `Optional[RequestContext]`)
  is injected for you and never shown to the model. Whatever the model sends
  under that name is discarded, so it cannot claim to be someone else. Any
  tool or provider can also call `current_context()` instead.
- It works the same for `run()` and `arun()`, under every orchestrator
  backend, and across the sync bridge. A provider (for example a tenant-aware
  gateway) reads `current_context()` in `chat()`; no wrapper needs to carry the
  tenant.
- The context is trusted, application-supplied data, not authorization: decide
  what a user may do from it, never from message text.
- It follows Python's context chain. A thread you start yourself starts empty;
  hand it over with `submit_with_context(executor, fn, ...)` (or
  `contextvars.copy_context().run`). Another process, such as an MCP server,
  does not see it.
- `correlation_id` is added to the `requisite.agent.run` span. User and tenant
  are not put on spans.

See [ADR-0043](docs/adr/0043-request-scoped-context.md).

### Multi-agent workflows

```python
from requisite import Agent, Workflow

research = Agent(name="Researcher", provider="openai")
writer = Agent(name="Writer", provider="openai")

workflow = Workflow()
workflow.add(research)
workflow.add(writer)

result = workflow.run("Research AI trends and write a summary.")
print(result.content)
```

Run agents in parallel against the same input instead of as a pipeline:

```python
workflow.parallel()
result = workflow.run("What is retrieval-augmented generation?")
```

Switch the execution engine — the `.add()` / `.run()` API never changes:

```python
workflow.use_langgraph()   # requires: pip install langgraph
result = workflow.run("Research AI trends and write a summary.")

workflow.use_crewai()      # requires: pip install crewai -- "sequential" only
workflow.use_autogen()     # requires: pip install autogen-agentchat autogen-core -- "sequential" + "supervisor"
workflow.use_adk()         # requires: pip install google-adk -- "sequential" + "supervisor"
workflow.use_openai_agents()   # requires: pip install openai-agents -- "sequential" + "supervisor"
workflow.use_strands()         # requires: pip install strands-agents -- "sequential" + "supervisor"
workflow.use_agent_framework() # requires: pip install agent-framework-core -- "sequential" + "supervisor"

workflow.use_native()      # back to the built-in, dependency-free engine
```

`langgraph`/`crewai`/`autogen`/`adk`/`openai_agents`/`strands`/`agent_framework`
are coordination-only backends — every actual model call still goes
through each agent's own configured provider (rate limiting, tools,
everything), never the third-party package's own LLM client. So
`use_openai_agents()` never calls OpenAI and `use_strands()` never calls
Bedrock: a Gemini or Ollama agent stays a Gemini or Ollama agent. See
[ADR-0027](docs/adr/0027-crewai-autogen-orchestrator-backends.md),
[ADR-0039](docs/adr/0039-adk-orchestrator-backend.md) and
[ADR-0040](docs/adr/0040-agent-sdk-orchestrator-backends.md) for which
strategy each backend supports and why. The Claude Agent SDK is
deliberately not one of them — it runs the Claude Code CLI as a
subprocess and has no model hook to put Requisite's providers under
(Anthropic is still a fully supported *provider*).

Let a supervisor agent delegate to a team of workers, addressed by name,
deciding when the task is done:

```python
supervisor = Agent(name="Supervisor", provider="openai")
researcher = Agent(name="Researcher", provider="openai")
writer = Agent(name="Writer", provider="openai")

workflow = Workflow().supervisor()
workflow.add(supervisor).add(researcher).add(writer)
result = workflow.run("Research AI trends and write a summary.")
```

The first agent added is the coordinator; every agent added after it is a
worker. `.planner()` works the same way, but the first agent decomposes
the task into an ordered plan up front instead of delegating round by
round. `.reflection()` takes a single agent that critiques and revises
its own output over several rounds.

`supervisor` also runs on the `langgraph` backend (`workflow.use_langgraph()`)
as a real conditional graph — `add_conditional_edges` routing to
whichever worker the coordinator delegates to, looping back for another
round — not a disguised Python loop. Same `.add()`/`.run()` call site
either way; see [ADR-0016](docs/adr/0016-langgraph-branching.md).

```python
workflow = Workflow().reflection()
workflow.add(writer)
result = workflow.run("Write a tagline for an AI framework.", max_rounds=3)
```

`.tree_of_thoughts()` branches and prunes a search tree of candidate
reasoning steps instead of following a single path — the first agent
evaluates, the rest generate candidates:

```python
evaluator = Agent(name="Evaluator", provider="openai")
thinker = Agent(name="Thinker", provider="openai")

workflow = Workflow().tree_of_thoughts()
workflow.add(evaluator).add(thinker)
result = workflow.run(
    "A train travels 60 miles in the first hour and 90 in the second. "
    "What is its average speed?",
    breadth=3, beam_width=2, max_depth=3,
)
```

Each level, `breadth` candidates are generated and scored together, then
pruned to the top `beam_width` before continuing — see
[ADR-0018](docs/adr/0018-tree-of-thoughts-strategy.md).

### Rate limiting

Free-tier and other quota-limited API keys often cap requests per
minute — set `RATE_LIMIT_RPM` (and, optionally, `RATE_LIMIT_MAX_WAIT_SECONDS`)
in `.env` and `AI`/`Agent` wait for capacity instead of letting the
provider reject the call:

```env
RATE_LIMIT_RPM=15
```

That covers a single `Agent`/`AI`. **Several agents that call the same
underlying API key share the same real quota**, so build one
`RateLimiter` and pass it to each of them explicitly — this is what a
multi-agent `Workflow` (research + writer + planner + supervisor, say)
needs to avoid exceeding the quota collectively even if each individual
agent looks fine on its own:

```python
from requisite import Agent, RateLimiter

shared_limit = RateLimiter(requests_per_minute=15)
research = Agent(name="Researcher", provider="gemini", rate_limiter=shared_limit)
writer = Agent(name="Writer", provider="gemini", rate_limiter=shared_limit)
```

### Cost-based spend limiting

`RateLimiter` paces call *rate*; `CostLimiter` caps real dollar
*spend*, independent of and composable with it. Pricing is a
caller-supplied function — no per-model price table is shipped or
maintained by the framework, since prices go stale faster than a
framework could realistically track them:

```python
from requisite import Agent, CostLimiter, cost_per_token

budget = CostLimiter(
    budget_usd=10.0,
    cost_fn=cost_per_token(prompt_rate_per_1k=0.15, completion_rate_per_1k=0.60),
)
agent = Agent(name="Assistant", provider="openai", cost_limiter=budget)
```

Share the same `CostLimiter` instance across every `Agent`/`AI` drawing
on one budget, the same sharing pattern `RateLimiter` uses. It's
reactive, not proactive: completion-token cost only exists once the
provider responds, so `budget_usd` can't be enforced strictly in
advance the way request *rate* can. A call already in flight when the
budget is reached is allowed to finish; every call after that raises
`CostLimitException` immediately, before reaching the provider. The
budget doesn't reset on its own — call `budget.reset()` on whatever
schedule you want (daily, monthly, a cron job). Only enforced on
`chat_response`/`achat_response` (and therefore `Agent.run`/`arun`'s
tool-calling loop) — streaming calls don't carry token usage data yet.
See [ADR-0038](docs/adr/0038-cost-based-rate-limiting.md).

### Skills

A skill is a reusable, higher-level capability (vs. a tool, which is
typically a single function). Skills expose themselves to the model as
tools automatically:

```python
from requisite.skills import BaseSkill

class ReadFileSkill(BaseSkill):
    def __init__(self):
        super().__init__(name="read_file", description="Read a text file's contents.")

    def run(self, path: str) -> str:
        with open(path) as f:
            return f.read()

agent = Agent(name="File Agent", provider="openai", skills=[ReadFileSkill()])
```

### Capabilities: declare *what*, not *which*

`agent.use_tool(specific_impl)` binds an agent to one concrete
implementation at write-time. `agent.requires("weather")` binds it to a
*name*, resolved at runtime against whichever implementation is
currently available — a native tool, an MCP server, a cloud API, or a
third-party plugin:

```python
from requisite import Agent

agent = Agent(name="Assistant", provider="openai")
agent.requires("weather", "internet_search", "filesystem")

result = agent.run("What's the weather in Tokyo?")
```

Three capabilities ship out of the box, backed by free/keyless APIs and
the local filesystem (see `requisite/capabilities/resolvers.py`):
`"filesystem"`, `"weather"`, `"internet_search"`.

Register a better provider for the same capability at a higher priority
and it takes over automatically — application code never changes:

```python
from requisite.capabilities import default_registry

default_registry.register(
    "weather",
    my_paid_weather_tool,
    provider_name="acme-weather",
    priority=10,
    is_available=lambda: bool(os.environ.get("ACME_API_KEY")),
)
# agent.requires("weather") now resolves to "acme-weather" when the key
# is set, and quietly falls back to the built-in provider otherwise.
```

This is the same interface + registry pattern used for providers and
orchestrators, one layer up: `CapabilityRegistry.resolve(name)` picks the
highest-priority provider whose `is_available()` currently returns
`True`, raising `CapabilityException` if none are.

### Plugins

Third-party packages register with any of the registries above the same
way first-party code does — no special `Plugin` class. Discover every
installed one (rather than manually importing each) by declaring it
under the `"requisite.plugins"` entry-point group and calling:

```python
from requisite.plugins import discover

result = discover()
print(result.loaded)   # names of plugins that registered successfully
print(result.failed)   # {name: error} for any that didn't -- one broken
                        # plugin never blocks the rest
```

Never automatic — nothing runs from a package you didn't ask to
discover. Also available as `requisite plugins` on the CLI. See
[`CONTRIBUTING.md`](CONTRIBUTING.md#writing-a-plugin) for how to write
one, [ADR-0017](docs/adr/0017-entry-point-plugin-discovery.md) for the
design, and [`PLUGINS.md`](PLUGINS.md) for the directory of published
third-party plugins.

### MCP integration

Connect to any MCP server (local via stdio, or remote via Streamable
HTTP) and its tools become capabilities like any other:

```python
from requisite import Agent
from requisite.mcp import MCPClient
from requisite.capabilities import default_registry as capabilities

# Local, subprocess-based MCP server
filesystem = MCPClient.stdio(
    name="filesystem",
    command="npx",
    args=["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allow"],
)
filesystem.register_as_capability(capabilities, capability="read_file")

# Remote MCP server
github = MCPClient.http(name="github", url="https://api.example.com/mcp", headers={"Authorization": "Bearer ..."})
github.register_as_capability(capabilities, capability="github")

agent = Agent(name="Assistant", provider="openai")
agent.requires("read_file", "github")  # agent can't tell these apart from native tools
```

You can also use an MCP server's tools directly, without going through
capabilities:

```python
tools = filesystem.discover_tools()
agent = Agent(name="Assistant", provider="openai", tools=tools)
```

Both transports were verified against real MCP servers during
development. By default, each tool call re-connects, calls, and
disconnects rather than holding a persistent session — see
[ADR-0004](docs/adr/0004-mcp-integration.md) for why. For repeated calls
to the same server in a tight loop, an opt-in persistent-session mode
avoids that reconnect cost — measured live: ~1000x faster for stdio,
~15x for HTTP:

```python
async with MCPClient.stdio(name="filesystem", command="npx", args=["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]) as filesystem:
    tools = await filesystem.adiscover_tools()
    result = await tools[0].aexecute(path="/tmp")
    # ... as many more calls as you like, all reusing the same session ...
```

Sync code can do the same with `with client:` (or `client.connect()` /
`client.close()`), which opens the session on a shared background loop so
`discover_tools()`, the other sync methods and a discovered tool's
`execute()` all reuse it. A session is bound to the loop it was opened on;
using it from a different loop raises instead of risking a hang — see
[ADR-0030](docs/adr/0030-mcp-persistent-session-mode.md) for the real
deadlock risk and [ADR-0041](docs/adr/0041-agent-owned-persistent-mcp-sessions.md)
for the sync support.

Or let the agent own the lifecycle — it connects on first use, reuses the
connections for every tool call, and closes them on `close()` / `with`:

```python
agent = Agent(name="Assistant", provider="gemini", mcp_clients=[filesystem])
with agent:                      # or: async with agent:
    agent.run("List the files in /tmp")
    agent.run("Now read the newest one")   # same server process, no reconnect
```

Measured against a real stdio server: 20 tool calls took 23.5 s with
per-call reconnect and 1.0 s agent-owned. Use either `run()` or `arun()` on
one agent, not both.

### Expose Requisite as an MCP server

The reverse direction: turn Requisite tools and agents *into* an MCP
server, so any MCP client (Claude Desktop, Claude Code, or Requisite's
own `MCPClient`) can use them:

```python
from requisite import Agent, MCPServer
from requisite.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 22C in {city}"

researcher = Agent(name="researcher", provider="openai")

server = MCPServer(name="my-tools", tools=[get_weather], agents=[researcher])
server.run_stdio()  # or: server.run_http(host="127.0.0.1", port=8000)
```

An agent exposed this way (`agents=[...]`, or `server.add_agent(...)`)
becomes a single MCP tool taking a `prompt` argument and returning its
final answer — `Agent.as_tool()` under the hood, reusable outside MCP
too. Both transports were verified end to end against Requisite's own
`MCPClient` (real subprocess, real HTTP port, including a real
provider call executing inside the server process) — see
[ADR-0015](docs/adr/0015-mcp-server-integration.md).

### RAG (Retrieval-Augmented Generation)

A retriever is a capability too — `agent.requires("knowledge_base")`
works exactly like `"weather"` or an MCP-backed tool:

```python
from requisite import Agent
from requisite.rag import Retriever
from requisite.rag.embeddings import OpenAIEmbeddingProvider
from requisite.rag.vectorstores import InMemoryVectorStore
from requisite.capabilities import default_registry as capabilities

retriever = Retriever(
    embedding_provider=OpenAIEmbeddingProvider(api_key="sk-..."),
    vector_store=InMemoryVectorStore(),  # zero-dependency default
)
retriever.add_texts([
    "Paris is the capital of France.",
    "The Eiffel Tower was completed in 1889.",
])

capabilities.register("knowledge_base", retriever.as_tool())

agent = Agent(name="Assistant", provider="openai")
agent.requires("knowledge_base")
print(agent.run("What's the capital of France?").content)
```

`add_texts` chunks each document (character-based, with overlap) before
embedding and storing it:

```python
retriever.add_texts(long_document_text, chunk_size=1000, chunk_overlap=200)
```

`InMemoryVectorStore` is the zero-dependency default — pure-Python cosine
similarity, fine for a few thousand chunks. Swap in a real vector
database the same way you'd swap a provider — construct it and pass it
to `Retriever(vector_store=...)`:

```python
from requisite.rag.vectorstores.pinecone import PineconeVectorStore
# pip install requisite-ai[pinecone]
vector_store = PineconeVectorStore(api_key="...", index_name="my-index", dimension=1536)

from requisite.rag.vectorstores.weaviate import WeaviateVectorStore
# pip install requisite-ai[weaviate]
vector_store = WeaviateVectorStore(url="https://my-cluster.weaviate.network", api_key="...")
```

See [ADR-0005](docs/adr/0005-rag-integration.md) for the interface
decomposition (embeddings / vector stores / retrievers are three
independent extension points) and why the in-memory default was chosen
over requiring a real vector DB from day one.

#### Access control

If different users may read different documents, **filtering is your
application's job**: Requisite gives you the mechanism, you decide who may
see what. Stamp each chunk with who can read it, then pass a `filter` on
every retrieval that serves that user:

```python
retriever = HybridRetriever(embedding_provider=..., vector_store=InMemoryVectorStore())
retriever.add_texts(
    [handbook, layoff_plan],
    metadatas=[{"groups": ["all"]}, {"groups": ["exec"]}],
    doc_ids=["handbook", "layoffs"],          # stable ids: "handbook:0", "layoffs:0", ...
)

mine = {"groups": {"$in": user_groups}}       # any-of: the chunk's groups overlap the user's
hits = retriever.retrieve("annual leave", filter=mine)

# For an agent, bind the filter into the tool. It is not a tool parameter,
# so the model can neither see nor change it -- build one tool per user.
tool = retriever.as_tool(filter=mine, source_key="doc_id")   # "[score=0.03 source=handbook#0] ..."
```

- The filter is applied to **every** retrieval path, including the keyword
  side of `HybridRetriever`, before scoring and fusion, so a restricted
  chunk cannot come back through any of them (and cannot influence the
  scores of allowed ones).
- Plain values mean exact equality; `{"$in": [...]}` means any-of. A missing
  key never matches and an empty list matches nothing; an unsupported
  operator raises instead of matching everything.
- **A call without `filter` sees everything.** Grounding or citation checks
  are not authorization: a retriever with no filter can pass every citation
  check while leaking restricted documents.
- Re-ingesting a document with the same `doc_id` overwrites its chunks; if it
  got shorter, delete the previously returned ids first.

See [ADR-0042](docs/adr/0042-access-controlled-retrieval.md).

### Memory: conversation history across separate calls

```python
from requisite import Agent
from requisite.memory import InProcessMemory

memory = InProcessMemory()
agent = Agent(name="Assistant", provider="openai", memory=memory, session_id="user-42")

agent.run("My name is Alex.")
result = agent.run("What's my name?")  # remembers "Alex" via `memory`
print(result.content)
```

`session_id` is required whenever `memory` is set — there's no implicit
"current user," so an agent with memory but no session_id fails at
construction time rather than silently sharing one conversation across
callers. When memory is configured, `run()`/`arun()` must be called with
a plain string (the new turn); prior history is loaded from `memory`
automatically. Only the user's turn and the agent's final answer are
persisted, not intermediate tool-call round-trips — see
[ADR-0002](docs/adr/0002-provider-kwargs-and-memory-integration.md) for
the reasoning.

`InProcessMemory` (dict-backed, lost on restart) is the zero-dependency
default. Implement `requisite.memory.base.BaseMemory` for a persistent
backend (Redis, SQLite, ...) — see `ROADMAP.md`.

### Conversation policies: keeping long histories bounded

A conversation that grows unbounded eventually blows past the model's
context window (or just gets expensive). `conversation_policy=` trims or
summarizes history once, before each `run()`/`arun()` call — independent
of whether `memory` is configured:

```python
from requisite import Agent
from requisite.memory import InProcessMemory, MessageCountPolicy

agent = Agent(
    name="Assistant",
    provider="openai",
    memory=InProcessMemory(),
    session_id="user-42",
    conversation_policy=MessageCountPolicy(max_messages=20),  # keep the most recent 20
)
```

For long-running conversations where you'd rather compress old context
than drop it, `SummarizingPolicy` collapses older messages into one
LLM-generated summary, keeping the most recent few verbatim:

```python
from requisite import AI
from requisite.memory import SummarizingPolicy

# A separate, cheaper AI instance for summarization is a reasonable choice --
# summarization quality requirements are usually lower than the agent's own task.
summarizer = AI(provider="groq", model="llama-3.3-70b-versatile")

agent = Agent(
    name="Assistant",
    provider="openai",
    memory=InProcessMemory(),
    session_id="user-42",
    conversation_policy=SummarizingPolicy(summarizer, max_messages=20, keep_recent=6),
)
```

See [ADR-0003](docs/adr/0003-prompt-templates-structured-logging-conversation-policy.md)
for why the policy is applied once per call rather than mid-tool-loop,
and why it doesn't change what gets persisted to `memory`.

### Prompt templates

```python
from requisite.prompts import ChatPromptTemplate

chat_template = ChatPromptTemplate.from_messages([
    ("system", "You are a {persona}."),
    ("user", "{question}"),
])

messages = chat_template.format_messages(persona="pirate", question="Where's the treasure?")
print(ai.chat(messages))
```

`ChatPromptTemplate.format_messages(...)` returns a plain `list[Message]`
— pass it to `ai.chat(...)` or `agent.run(...)` exactly like any other
message sequence. For a single string instead of a full conversation,
use `PromptTemplate`:

```python
from requisite.prompts import PromptTemplate

translate = PromptTemplate.from_template("Translate to {language}: {text}")
print(ai.chat(translate.format(language="French", text="Good morning")))

# Pre-fill some variables now, leave the rest for later:
french_translator = translate.partial(language="French")
print(ai.chat(french_translator.format(text="Good night")))
```

Register named templates for reuse across an application with
`PromptTemplateRegistry`.

### Structured logging

Every framework module logs through the standard library
(`logging.getLogger("requisite.<subpackage>")`). Opt into JSON output
with one call, wherever your application configures logging — this is
never done automatically by the framework:

```python
from requisite.telemetry import configure_logging

configure_logging(level="INFO", json_format=True)
```

```json
{"timestamp": "...", "level": "DEBUG", "logger": "requisite.capabilities", "message": "Resolved capability 'weather' -> 'open-meteo'", "capability": "weather", "provider_name": "open-meteo"}
```

Any `extra={...}` fields passed to a log call are merged into the JSON
payload automatically — the same log call produces a readable line with
the default formatter and a structured payload with `json_format=True`.

### Streaming & async

```python
for token in ai.stream("Write a haiku about distributed systems."):
    print(token, end="")

text = await ai.achat("Hello!")
async for token in ai.astream("Hello, streamed!"):
    print(token, end="")

result = await agent.arun("What's the weather in Paris?")
result = await workflow.arun("Research AI trends.")
```

### Conversation history

```python
from requisite import Message

history = [
    Message.user("My name is Alex."),
    Message.assistant("Nice to meet you, Alex!"),
    Message.user("What's my name?"),
]
print(ai.chat(history))
```

See `examples/` for complete, runnable scripts covering each of the above.

## Architecture

```
requisite/
├── core/           # Provider-agnostic data models (Message, ChatResponse,
│                   # ToolCall, ...) and the AIException hierarchy
├── config/         # Settings (pydantic-settings, reads .env)
├── providers/      # BaseProvider interface + OpenAI, Anthropic, Gemini, Groq,
│                   # Azure OpenAI, OpenRouter, Together AI, Ollama
│                   # + ProviderRegistry (extensible, DI-friendly)
├── tools/          # Tool, @tool decorator, ToolRegistry, JSON Schema derivation
├── skills/         # BaseSkill, SkillRegistry -- reusable higher-level capabilities
├── capabilities/   # CapabilityRegistry -- resolve a named capability (e.g.
│                   # "weather") to whichever implementation is available
├── mcp/            # BaseMCPClient + MCPClient (stdio + Streamable HTTP)
│                   # + MCPClientRegistry -- bridges MCP tools into capabilities
│                   # + MCPServer -- reverse direction, expose Requisite as a server
├── rag/            # BaseEmbeddingProvider, BaseVectorStore, BaseRetriever
│                   # + Retriever (dense) + InMemory/Pinecone/Weaviate vector stores
├── memory/         # BaseMemory + InProcessMemory + MemoryRegistry, plus
│                   # BaseConversationPolicy (MessageCountPolicy, SummarizingPolicy)
├── prompts/        # PromptTemplate, ChatPromptTemplate, PromptTemplateRegistry
├── telemetry/      # Structured (JSON) logging -- opt-in, never automatic
├── agents/         # Agent (tool-calling loop, .requires(), optional memory) + AgentRegistry
├── orchestrators/  # BaseOrchestrator interface + native (sequential, parallel,
│                   # reflection, planner, supervisor) and langgraph backends
│                   # + OrchestratorRegistry
├── workflows/      # Workflow -- the small, ergonomic multi-agent facade
├── cli/            # requisite init/providers/capabilities/agents/plugins/chat --
│                   # see the CLI section above and ADR-0014
├── plugins.py      # discover() -- entry-point plugin discovery, see ADR-0017
└── ai.py           # The `AI` facade -- the class most users touch directly
```

Every layer follows the same pattern: a small abstract interface
(`BaseProvider`, `BaseOrchestrator`, ...), one or more concrete
implementations, and a plain, instantiable registry (not a singleton)
mapping names to constructors. That's what makes each of the following a
*configuration* change rather than a *code* change:

- `AI(provider="openai")` → `AI(provider="gemini")`
- `Workflow(orchestrator="native")` → `workflow.use_langgraph()`
- `agent.use_tool(specific_impl)` → `agent.requires("weather")`

See **[`ARCHITECTURE.md`](ARCHITECTURE.md)** for the full dependency
diagram, request-flow walkthroughs (a chat call, an agent's tool-calling
loop, capability resolution, a multi-agent workflow), and the design
decisions behind them. See **[`CONTRIBUTING.md`](CONTRIBUTING.md)** for
the step-by-step to add a new provider, orchestrator backend, or
capability resolver.

## Error handling

All framework exceptions inherit from `AIException`:

```
AIException
├── ConfigurationException   # missing/invalid config, unknown provider/orchestrator name
├── ProviderException        # provider SDK call failed (wraps the original error)
├── ToolException            # a tool wasn't found, or raised while executing
├── SkillException           # a skill wasn't found, or raised while executing
├── AgentException           # agent execution failed (e.g. max_iterations exceeded)
├── CapabilityException      # a required capability has no available provider
├── PromptException          # a prompt template was rendered without a required variable
└── MCPException              # an MCP server call/discovery failed, or a capability bridge found no matching tool
```

Provider SDK errors are never swallowed — they're wrapped with `provider`
and `original_error` attached, and re-raised via `raise ... from original_error`
so the original traceback is preserved.

## Testing

```bash
pytest
```

Tests never hit the network: the OpenAI and Gemini SDKs are faked via
`sys.modules` injection, and the `AI` / `Agent` / `Workflow` facades are
tested against fully in-memory fake providers.

## Roadmap

Implemented: 8 providers (OpenAI, Anthropic, Gemini, Groq, Azure OpenAI,
OpenRouter, Together AI, Ollama), structured outputs, tool calling,
skills, capability resolution (`agent.requires(...)`), MCP client and
server integration (stdio + Streamable HTTP, both directions, plus an
opt-in persistent-session client mode), RAG (embeddings, in-memory /
Pinecone / Weaviate vector stores, dense/BM25/hybrid retrieval,
re-ranking, context compression), memory + conversation policies
(`Agent(memory=..., conversation_policy=...)`), prompt templates,
structured logging plus OpenTelemetry tracing/metrics, agents +
registry, multi-agent workflows (sequential, parallel, reflection,
planner, supervisor, critic, consensus, debate, map-reduce,
hierarchical, tree-of-thoughts, reflexion, and graph -- all thirteen
run on both the native and langgraph backends; sequential on CrewAI,
AutoGen, ADK, the OpenAI Agents SDK, Strands, and Microsoft Agent
Framework, supervisor also on every one of those except CrewAI),
entry-point plugin discovery, an
official plugin directory (`PLUGINS.md`).

See [`ROADMAP.md`](ROADMAP.md) for the full, per-layer status table
(providers, orchestration strategies, MCP, memory, RAG, ...) and what's
explicitly out of scope. See [`FEATURES.md`](FEATURES.md) for the same
information organized as a line-by-line checklist against the original
project vision.

## Contributing

Contributions are welcome:

- [`CONTRIBUTING.md`](CONTRIBUTING.md) — dev setup, running checks, and
  step-by-step guides for adding a provider, orchestrator backend, or
  capability resolver.
- [`ARCHITECTURE.md`](ARCHITECTURE.md) — how the framework fits together
  and why: the interface + registry pattern, request-flow walkthroughs,
  design decisions.
- [`docs/adr/`](docs/adr/) — Architecture Decision Records: the formal
  rationale behind core interfaces, extension points, plugin discovery,
  configuration model, and the `requisite-core` vs. optional-integrations
  boundary. Start with [ADR-0001](docs/adr/0001-core-architecture-and-interfaces.md).
- [`DEVELOPMENT.md`](DEVELOPMENT.md) — coding standards, testing
  philosophy, docstring format, logging/error-handling conventions,
  versioning policy.
- [`ROADMAP.md`](ROADMAP.md) — what's shipped, planned, or out of scope.
- [`PLUGINS.md`](PLUGINS.md) — the directory of published third-party
  plugins, and how to get yours listed.

Please also read the [Code of Conduct](CODE_OF_CONDUCT.md). Security
issues should go through [`SECURITY.md`](SECURITY.md), not a public issue.

See [`CHANGELOG.md`](CHANGELOG.md) for release history.

## License

MIT — see [`LICENSE`](LICENSE).
