Efficient token workflow engine is an extensible framework for building configurable multi-agent AI workflows.
It allows you to:
-
Define workflows declaratively using TOML.
-
Compose AI agents with reusable capability modules.
-
Support multiple LLM providers.
-
Build conditional execution graphs with LangGraph.
-
Optimize token usage by routing tasks to specialized agents.
-
the runtime pipeline is defined in the CONFIGURATION environnement variable.
GET /- basic service metadataGET /health- health checkPOST /chat- main question endpoint
The runtime graph is assembled at startup from config.toml.
For example:
- The
generatoragent receives the user question, the database schema context, and the conversation memory. - It produces a MySQL query.
- The database module executes the query and stores the results in the graph state.
- The graph routes to the
explaineragent, which turns the result into a concise French answer. - If the graph marks an error, it routes to the
exceptionagent instead.
Main implementation files:
app/main.py- FastAPI app startup and graph initializationapp/api/routes.py- HTTP routesapp/agents/- agent registry, provider factory, and execution wrapperapp/modules/- database and memory modulesapp/prompt/- promptsapp/workflows/- LangGraph wiring and routingapp/tasks/- scheduler helpers for memory reset and LLM refresh
- Python 3.9+
- A MySQL-compatible database
- One supported LLM provider:
OPENAI_API_KEYGROQ_API_KEY- Ollama does not need an API key
The application reads these variables at runtime:
CONFIGURATION- path to the pipeline config file, usuallyconfig.tomlDB_USERNAMEDB_PASSWORDDB_HOSTDB_PORTDATABASEOPENAI_API_KEY- required if you use the OpenAI providerGROQ_API_KEY- required if you use the Groq providerMEMORY_TIMEOUT_SECONDS- optional inactivity timeout for memory cleanup
Example .env:
CONFIGURATION=config.toml
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=3306
DATABASE=your_database_name
OPENAI_API_KEY=sk-...
GROQ_API_KEY=gsk-...
MEMORY_TIMEOUT_SECONDS=600config.toml defines the agents and edges used by LangGraph.
Example flow:
generatoruses thesql_promptand thedatabase+memorymodulesexplaineruses thenlp_promptand thememorymoduleexceptionuses the same natural-language prompt for fallback responses
If you need to change the model, provider, prompt, or attached modules, edit config.toml.
git clone https://github.com/Rayan-ouer/minimal-token-db-api.git
cd minimal-token-db-api
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"question": "Which region had the highest sales last year?",
"session_id": 1
}'POST /chat returns the graph state. The important field is the final output, which contains the generated answer.
app/
├── agents/ # agent registry, factory, and provider definitions
├── api/ # HTTP routes
├── modules/ # database and memory modules
├── prompt/ # prompts and schema metadata
├── schemas/ # typed state and request models
├── tasks/ # scheduler helpers
└── workflows/ # LangGraph graph and routing
- The database connector expects MySQL connection details.
- The SQL prompt is strict about MySQL syntax and automatic
LIMITenforcement. - The response prompt is in French and keeps answers concise.