FetchGraph
One semantic access layer for your AI agents.
Describe your data once. Let any agent query it.
AI agents can already call databases, APIs, vector stores, and MCP tools.
The harder problem is teaching every agent what your data means:
- where customers, orders, products, documents, or metrics live,
- how those entities relate,
- which fields and operations are valid,
- and how a natural-language question should be translated into retrieval.
If every agent has to rediscover that from raw schemas and tool descriptions, the same retrieval logic gets rebuilt again and again.
FetchGraph moves that knowledge into a reusable layer.
Agents / Copilots / Workflows
│
▼
┌─────────────┐
│ FetchGraph │
│ semantic │
│ access layer│
└──────┬──────┘
│
┌───────┼────────┐
▼ ▼ ▼
SQL APIs RAG
/ files
You describe each data source as a provider: what it contains, what it can do, and how it may be queried.
Given a natural-language task, FetchGraph can then:
- decide which providers are relevant,
- build a structured retrieval plan,
- validate and normalize provider-specific selectors,
- fetch the required data,
- fit the evidence into a context budget,
- and pass the assembled context to an LLM to produce the result.
The goal is simple:
Adding the second, tenth, or hundredth agent should not require teaching each of them your data architecture again.
Why FetchGraph?
Imagine your company has:
- customers in one database,
- orders in another,
- product information behind an API,
- documentation in a vector index,
- and several agents that need different combinations of that data.
You can give every agent direct access to all of those systems and let it figure everything out at runtime.
That works well for simple cases.
But as data sources and agents multiply, every agent starts solving the same questions:
Where does this information live?
Which entity should I query?
Which relation should I follow?
Which filters are valid?
Do I need SQL, semantic search, or both?
FetchGraph makes those answers reusable.
For example, a provider can describe a relational source roughly as:
Customers
- id
- segment
- country
Orders
- customer_id
- order_date
- amount
Customer -> Orders via customer_id
Supported operations:
- filter
- relation traversal
- aggregation
- semantic search
Then an application can ask:
Which products grew fastest among enterprise customers in Germany last quarter?
The planner can use the provider descriptions to determine the relevant entities, relations, filters, and aggregations instead of requiring that logic to be hard-coded into the application.
FetchGraph vs. MCP, direct SQL, and RAG
FetchGraph is not intended to replace any of them.
MCP
MCP is a great way to expose tools and resources to agents.
FetchGraph solves a different problem:
MCP: What can the agent call?
FetchGraph: What information does this task need, and how should it be retrieved?
A FetchGraph application can be wrapped as a tool or exposed over MCP so multiple agents share the same data model and retrieval behavior.
Direct SQL
For one agent and one well-understood database, letting the model inspect the schema and write SQL directly may be simpler.
FetchGraph becomes useful when you want the knowledge about entities, relations, valid operations, and retrieval rules to be shared across agents and sources, rather than rediscovered by every model invocation.
RAG
Traditional RAG is excellent when the problem is:
question -> similarity search -> chunks -> prompt
FetchGraph is useful when retrieval also involves structured operations:
intent
-> choose source
-> choose entities
-> filters / relations / aggregations / semantic search
-> fetch evidence
-> context
Vector search can simply be one of the provider capabilities.
Core abstraction: providers
A provider exposes two things:
1. How to fetch data
provider.fetch(
feature_name,
selectors={...},
)
2. How the planner is allowed to query it
ProviderInfo(
name="orders",
description="Orders and customer purchases",
capabilities=["query", "aggregate"],
selectors_schema={...},
examples=[...],
)
FetchGraph builds a catalog from these descriptions and gives it to the planner.
The planner produces structured fetch specifications rather than arbitrary application code:
{
"required_context": ["orders"],
"context_plan": [
{
"provider": "orders",
"mode": "slice",
"selectors": {
"op": "query",
"root_entity": "orders",
"limit": 20
},
"max_tokens": 2000
}
]
}
Providers remain responsible for executing those selectors against the real system.
That means a provider may wrap a database client, an ODBC connection, an HTTP API, a vector store, a local dataframe, or another retrieval system without exposing those runtime objects to the planner.
Quick start
Install
pip install fetchgraph
Retrieve evidence for any agent
pip install 'fetchgraph[retrieval]'
from fetchgraph import FetchGraph
graph = FetchGraph("/absolute/path/fetchgraph.toml")
bundle = graph.retrieve("How many orders are in the shop?", source="shop")
print(bundle.evidence[0].data)
print(bundle.plan.context_plan[0].selectors)
Retrieval returns structured data, provenance, the executed plan, and diagnostics.
Use graph.answer(question, source="shop") to add answer synthesis.
Async applications can await graph.aretrieve(...) and graph.aanswer(...).
Module-level fetchgraph.retrieve(...) and fetchgraph.answer(...) accept
config=..., or read the configuration path from FETCHGRAPH_CONFIG.
See the API and configuration contract.
MCP server
Connect configured sources to Codex, OpenCode, or another MCP client:
pip install 'fetchgraph[mcp]'
fetchgraph-mcp --config /absolute/path/fetchgraph.toml --check-config
codex mcp add fetchgraph -- fetchgraph-mcp --config /absolute/path/fetchgraph.toml
Configure an inference endpoint, model, and source in TOML. The server provides
fetchgraph_catalog, fetchgraph_retrieve, fetchgraph_ask, and
fetchgraph_read_evidence.
See the MCP specification for configuration
examples, OpenCode setup, and source adapter contracts.
Quick Start
Selectors are JSON-only
Providers receive a selectors argument that must be JSON-serializable. The
shared alias SelectorsDict (exported from fetchgraph.relational.types) represents
Dict[str, JSONValue] and is used across protocols and models. The planner/LLM
produces this structure, so do not place runtime-only Python objects (e.g.
connections, DataFrames) into selectors; pass such hints through **kwargs
instead. Providers can publish the expected shape via ProviderInfo.selectors_schema
(a JSON Schema) and optional examples containing stringified JSON payloads.
Relational providers require selectors to include a string field "op" that
chooses the operation (e.g., "schema", "semantic_only", "query"). The
complete set of supported shapes is described by the schema returned from
RelationalDataProvider.describe().
import json
from fetchgraph import (
ProviderInfo,
TaskProfile,
create_generic_agent,
)
class CustomerProvider:
name = "customers"
def describe(self) -> ProviderInfo:
return ProviderInfo(
name=self.name,
description="Customer accounts, subscriptions, and billing history.",
capabilities=["lookup"],
selectors_schema={
"type": "object",
"properties": {
"customer_id": {"type": "string"},
},
"additionalProperties": False,
},
examples=[
'{"customer_id": "cus_123"}',
],
)
def fetch(self, feature_name, selectors=None, **kwargs):
customer_id = (selectors or {}).get("customer_id")
# Replace with your DB/API call.
return load_customer(customer_id)
def serialize(self, obj):
return json.dumps(obj, default=str)
def llm(prompt: str, sender: str) -> str:
# OpenAI, Anthropic, a local model, LiteLLM, etc.
return my_model(prompt)
agent = create_generic_agent(
llm_invoke=llm,
providers={
"customers": CustomerProvider(),
},
task_profile=TaskProfile(
task_name="Customer support",
goal="Answer questions using available customer data.",
output_format="Plain text",
),
saver=lambda name, result: None,
)
answer = agent.run(
"Why was customer cus_123 charged twice?"
)
print(answer)
The application does not hard-code when the customer provider should be used or which selector should be sent.
The provider describes itself:
customers
├── what data it contains
├── what it can do
├── selector schema
└── examples
The planner uses that contract to decide whether the provider is needed and how to query it.
What happens during a run?
The generic agent follows this flow:
TASK
│
▼
PLAN
│ choose providers + selectors
▼
FETCH
│ execute provider contracts
▼
PACK
│ keep context within a token budget
▼
ASSESS / REFETCH (optional)
│
▼
SYNTHESIZE
│
▼
VERIFY / REFINE (optional)
│
▼
RESULT
The planning and retrieval steps are explicit, which makes them easier to inspect and evaluate separately from final answer generation.
Relational data
FetchGraph includes relational abstractions for structured business data.
The public API includes:
EntityDescriptorColumnDescriptorRelationDescriptorRelationalDataProviderSqlRelationalDataProviderPandasRelationalDataProviderCompositeRelationalProvider
Relational providers can describe entities and relations to the planner and support structured operations such as filtering, selecting fields, aggregations, relation traversal, and semantic clauses.
Internally, the planning pipeline can normalize selectors, validate them, bind field references to the schema, normalize aggregations, and retry planning when a generated plan cannot be executed.
This is the main reason to use FetchGraph instead of simply putting a raw database schema into every agent prompt: the data-access model becomes a reusable contract with a validation and execution layer behind it.
Semantic retrieval
Semantic search is a provider capability rather than a special application architecture.
FetchGraph currently includes:
- a lightweight CSV semantic backend for Pandas providers,
- pluggable embedding models,
- pgvector / LangChain vector-store integration,
- semantic clauses inside relational requests.
This allows an application to combine structured and semantic retrieval rather than choosing between "SQL" and "RAG" at the application level.
Selectors
Provider selectors are JSON-serializable structures generated during planning.
ContextFetchSpec(
provider="orders",
mode="slice",
selectors={
"op": "query",
"root_entity": "orders",
},
)
Providers can publish the expected selector shape through ProviderInfo.selectors_schema and examples through ProviderInfo.examples.
Runtime-only Python objects such as database connections, DataFrames, or model clients should stay inside the provider or be passed as runtime hints — not inside planner-generated selectors.
Current capabilities
- schema-driven provider catalog
- LLM-generated structured retrieval plans
- pluggable providers for heterogeneous sources
- JSON Schema-guided selectors
- relational entities and relations
- filtering and aggregations
- structured + semantic retrieval
- SQL and Pandas relational providers
- composite relational providers
- bounded context packing
- optional assess/refetch loop
- optional verification/refinement
- replay / planning diagnostics in the normalization pipeline
- no agent-framework lock-in
When should I use FetchGraph?
FetchGraph is a good fit when:
- several agents need access to the same corporate data,
- data is spread across heterogeneous systems,
- questions require more than document similarity search,
- structured filters, joins, or aggregations matter,
- you want retrieval logic to be inspectable and reusable,
- or you want to separate context planning from the main agent reasoning loop.
You probably do not need FetchGraph if:
- you have one small corpus and ordinary top-k RAG is enough,
- you have one simple database and are happy to let one strong model write SQL directly,
- or there is no meaningful data model worth sharing across applications.
Examples
Working examples live under:
examples/
├── demo_qa/
└── retail_orders/
examples/demo_qa contains a schema-driven QA testbed with planning artifacts and evaluation cases.
examples/retail_orders demonstrates questions over relational business data.
Direction
The long-term direction is to make the semantic layer cheaper to create and richer to reuse.
One natural extension is schema introspection and ontology-assisted provider generation: deriving an initial agent-readable model from database schemas, relationships, metadata, and existing corporate glossaries, then letting humans enrich it where business semantics cannot be inferred reliably.
That is a direction, not a requirement for using FetchGraph today.
The core invariant remains:
Describe your data once. Reuse that knowledge across agents.
License
MIT
Metadata
Release files for fetchgraph 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fetchgraph-0.3.0.tar.gz | 172.7 kB | With provenance | Details for fetchgraph-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fetchgraph-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for fetchgraph-0.3.0-py3-none-any.whl |
Total release size: 335.6 kB
Release files / fetchgraph-0.3.0.tar.gz
| Download URL | fetchgraph-0.3.0.tar.gz |
|---|---|
| Size | 172.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
712a5c410b5f06d7665e9d3ce5fdfef23441ac83a05829cd26e585ad66aa6067
|
|
BLAKE2b-256 checksum How to use checksums |
088f3768ab9f41588bb57090e440972bfae7268736b37fe14c678baa89625f5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / fetchgraph-0.3.0-py3-none-any.whl
| Download URL | fetchgraph-0.3.0-py3-none-any.whl |
|---|---|
| Size | 162.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9c0859badc0d311c5dfe9f1640085c9b9e35e3e76526122dedcc10f283d1fc0
|
|
BLAKE2b-256 checksum How to use checksums |
a83c8676401c67add651e012032bf794414420b0726356a2c59ef676edf22751
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for fetchgraph 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fetchgraph-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.