draco-harness 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. draco_harness-0.1.0/LICENSE +21 -0
  2. draco_harness-0.1.0/PKG-INFO +194 -0
  3. draco_harness-0.1.0/README.md +143 -0
  4. draco_harness-0.1.0/pyproject.toml +75 -0
  5. draco_harness-0.1.0/setup.cfg +4 -0
  6. draco_harness-0.1.0/src/draco/__init__.py +18 -0
  7. draco_harness-0.1.0/src/draco/adapters/__init__.py +6 -0
  8. draco_harness-0.1.0/src/draco/adapters/ingestion.py +35 -0
  9. draco_harness-0.1.0/src/draco/adapters/langgraph.py +57 -0
  10. draco_harness-0.1.0/src/draco/adapters/langgraph_checkpoint.py +133 -0
  11. draco_harness-0.1.0/src/draco/adapters/model_provider.py +44 -0
  12. draco_harness-0.1.0/src/draco/adapters/providers/__init__.py +1 -0
  13. draco_harness-0.1.0/src/draco/adapters/providers/_http.py +29 -0
  14. draco_harness-0.1.0/src/draco/adapters/providers/anthropic.py +50 -0
  15. draco_harness-0.1.0/src/draco/adapters/providers/openai_compat.py +46 -0
  16. draco_harness-0.1.0/src/draco/adapters/retrieval.py +97 -0
  17. draco_harness-0.1.0/src/draco/agents/__init__.py +10 -0
  18. draco_harness-0.1.0/src/draco/agents/registry.py +51 -0
  19. draco_harness-0.1.0/src/draco/agents/router.py +155 -0
  20. draco_harness-0.1.0/src/draco/core/__init__.py +25 -0
  21. draco_harness-0.1.0/src/draco/core/budget.py +75 -0
  22. draco_harness-0.1.0/src/draco/core/config.py +68 -0
  23. draco_harness-0.1.0/src/draco/core/context.py +125 -0
  24. draco_harness-0.1.0/src/draco/core/errors.py +86 -0
  25. draco_harness-0.1.0/src/draco/core/events.py +74 -0
  26. draco_harness-0.1.0/src/draco/core/identity.py +35 -0
  27. draco_harness-0.1.0/src/draco/core/policy.py +57 -0
  28. draco_harness-0.1.0/src/draco/core/protocols.py +10 -0
  29. draco_harness-0.1.0/src/draco/core/results.py +138 -0
  30. draco_harness-0.1.0/src/draco/harness/__init__.py +3 -0
  31. draco_harness-0.1.0/src/draco/harness/instrument.py +95 -0
  32. draco_harness-0.1.0/src/draco/harness/persistence.py +34 -0
  33. draco_harness-0.1.0/src/draco/harness/runner.py +426 -0
  34. draco_harness-0.1.0/src/draco/observability/__init__.py +2 -0
  35. draco_harness-0.1.0/src/draco/observability/otel.py +47 -0
  36. draco_harness-0.1.0/src/draco/observability/redaction.py +35 -0
  37. draco_harness-0.1.0/src/draco/observability/trace.py +72 -0
  38. draco_harness-0.1.0/src/draco/plugins/__init__.py +2 -0
  39. draco_harness-0.1.0/src/draco/plugins/registry.py +198 -0
  40. draco_harness-0.1.0/src/draco/plugins/services.py +60 -0
  41. draco_harness-0.1.0/src/draco/policies/__init__.py +3 -0
  42. draco_harness-0.1.0/src/draco/policies/guardrails.py +31 -0
  43. draco_harness-0.1.0/src/draco/policies/ratelimit.py +76 -0
  44. draco_harness-0.1.0/src/draco/py.typed +0 -0
  45. draco_harness-0.1.0/src/draco/security/__init__.py +5 -0
  46. draco_harness-0.1.0/src/draco/security/audit.py +29 -0
  47. draco_harness-0.1.0/src/draco/security/authorization.py +90 -0
  48. draco_harness-0.1.0/src/draco/security/crypto.py +58 -0
  49. draco_harness-0.1.0/src/draco/security/secrets.py +48 -0
  50. draco_harness-0.1.0/src/draco/state/__init__.py +16 -0
  51. draco_harness-0.1.0/src/draco/state/_sql.py +226 -0
  52. draco_harness-0.1.0/src/draco/state/memory.py +93 -0
  53. draco_harness-0.1.0/src/draco/state/postgres.py +125 -0
  54. draco_harness-0.1.0/src/draco/state/retention.py +33 -0
  55. draco_harness-0.1.0/src/draco/state/sqlite.py +99 -0
  56. draco_harness-0.1.0/src/draco/state/stores.py +101 -0
  57. draco_harness-0.1.0/src/draco/tools/__init__.py +17 -0
  58. draco_harness-0.1.0/src/draco/tools/contracts.py +120 -0
  59. draco_harness-0.1.0/src/draco/tools/execution.py +181 -0
  60. draco_harness-0.1.0/src/draco/tools/mcp.py +109 -0
  61. draco_harness-0.1.0/src/draco/tools/native.py +45 -0
  62. draco_harness-0.1.0/src/draco/tools/registry.py +27 -0
  63. draco_harness-0.1.0/src/draco/tools/safety.py +14 -0
  64. draco_harness-0.1.0/src/draco_harness.egg-info/PKG-INFO +194 -0
  65. draco_harness-0.1.0/src/draco_harness.egg-info/SOURCES.txt +66 -0
  66. draco_harness-0.1.0/src/draco_harness.egg-info/dependency_links.txt +1 -0
  67. draco_harness-0.1.0/src/draco_harness.egg-info/requires.txt +32 -0
  68. draco_harness-0.1.0/src/draco_harness.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amartya Ranjan and Draco contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: draco-harness
3
+ Version: 0.1.0
4
+ Summary: Embeddable agent runtime: harness, routing, tools, security, state and observability, with optional adapters
5
+ Author: Amartya Ranjan
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AmartyaRanjan/Draco
8
+ Project-URL: Documentation, https://github.com/AmartyaRanjan/Draco/blob/main/docs/README.md
9
+ Project-URL: Source, https://github.com/AmartyaRanjan/Draco
10
+ Project-URL: Issues, https://github.com/AmartyaRanjan/Draco/issues
11
+ Project-URL: Changelog, https://github.com/AmartyaRanjan/Draco/blob/main/docs/DRACO_CHANGELOG.md
12
+ Project-URL: Security Policy, https://github.com/AmartyaRanjan/Draco/blob/main/SECURITY.md
13
+ Keywords: rag,agents,llm,harness,orchestration,retrieval,langgraph,tool-use,multi-tenant
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: pydantic>=2.6
27
+ Provides-Extra: agents
28
+ Requires-Dist: langgraph>=1.0; extra == "agents"
29
+ Requires-Dist: langchain-core; extra == "agents"
30
+ Requires-Dist: langgraph-checkpoint-sqlite>=2.0; extra == "agents"
31
+ Provides-Extra: providers
32
+ Requires-Dist: httpx>=0.27; extra == "providers"
33
+ Provides-Extra: mcp
34
+ Requires-Dist: mcp>=1.0; extra == "mcp"
35
+ Provides-Extra: postgres
36
+ Requires-Dist: psycopg[binary]>=3.1; extra == "postgres"
37
+ Provides-Extra: crypto
38
+ Requires-Dist: cryptography>=42; extra == "crypto"
39
+ Provides-Extra: otel
40
+ Requires-Dist: opentelemetry-api; extra == "otel"
41
+ Requires-Dist: opentelemetry-sdk; extra == "otel"
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=8; extra == "dev"
44
+ Requires-Dist: ruff; extra == "dev"
45
+ Requires-Dist: mypy; extra == "dev"
46
+ Requires-Dist: pip-audit; extra == "dev"
47
+ Provides-Extra: docs
48
+ Requires-Dist: mkdocs>=1.6; extra == "docs"
49
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
50
+ Dynamic: license-file
51
+
52
+ # 🐉 Draco
53
+
54
+ > An execution harness for RAG and agent systems.
55
+
56
+ [![CI](https://github.com/AmartyaRanjan/Draco/actions/workflows/ci.yml/badge.svg)](https://github.com/AmartyaRanjan/Draco/actions/workflows/ci.yml)
57
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
58
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)
59
+ ![Status: alpha](https://img.shields.io/badge/status-alpha-orange)
60
+
61
+ [📖 Documentation](docs/README.md) · [🤝 Contributing](CONTRIBUTING.md) · [🛡️ Security](SECURITY.md) · [🗺️ Roadmap](docs/architecture/roadmap.md) · [📜 Changelog](docs/DRACO_CHANGELOG.md)
62
+
63
+ ---
64
+
65
+ ## 🏗️ Overview
66
+
67
+ Draco is a lightweight Python package that runs any async workload under one lifecycle. Its only hard dependency is `pydantic`. It provides:
68
+ - **Access control:** trusted identity, role-based authorization and default-deny tool policies.
69
+ - **Limits:** budgets, rate limits and deadlines.
70
+ - **Reliability:** idempotency and resumable steps.
71
+ - **Tracing:** redacted traces.
72
+ - **Durable state:** in-memory, SQLite or PostgreSQL.
73
+
74
+ It includes an agent registry and router, and a guarded tool runtime for native tools and, optionally, MCP tools. It also ships adapters for LangGraph, OpenAI-compatible providers and Anthropic.
75
+
76
+ > 🧩 **Built on Draco:** [draco-rag](https://github.com/AmartyaRanjan/draco-rag) is a FastAPI RAG and agent service that runs every chat, agent and resume request as a Draco workload. It started out in this repository as the starter app and now lives on its own.
77
+
78
+ ---
79
+
80
+ ## 🛠️ The Contract
81
+
82
+ ```python
83
+ Workload = Callable[[ExecutionContext, Any], Awaitable[Any]]
84
+ ```
85
+ Anything matching this shape can be registered with the `Harness`:
86
+
87
+ ```python
88
+ import asyncio
89
+ from draco import Harness, Identity
90
+
91
+ async def greeter(ctx, name):
92
+ return f"hello {name}"
93
+
94
+ async def main():
95
+ h = Harness()
96
+ h.register("greeter", greeter)
97
+ r = await h.run("greeter", "world", identity=Identity("alice", "acme"))
98
+ print(r.status, r.output, r.execution_id) # Status.completed hello world <id>
99
+
100
+ asyncio.run(main())
101
+ ```
102
+ `run()` always returns an `ExecutionResult` (`completed` | `failed` | `cancelled` | `timeout` | `budget_exhausted` | `handoff` | `waiting`). Failures are never reported as success; `result.raise_for_status()` re-raises them as typed `DracoError`.
103
+
104
+ ## 🏛️ Architecture Layers
105
+
106
+ | Package | Responsibility | Dependencies |
107
+ |---|---|---|
108
+ | `draco.core` | `ExecutionContext`, `Identity`, `Policy`, budgets, results, typed errors, events | `pydantic` |
109
+ | `draco.harness` | Lifecycle: identity, auth, guardrails, execution, deadlines, persistence, `resume()` | |
110
+ | `draco.agents` | `AgentRegistry`, `Router`, handoffs, delegation, loop/depth limits | |
111
+ | `draco.tools` | `Tool`, `ToolRegistry`, `ToolRuntime` (policy, retries, untrusted output), MCP tools | `draco-harness[mcp]` |
112
+ | `draco.security` | `Authorizer`, audit events, `Secret`, `FernetCipher` (encryption at rest) | `draco-harness[crypto]` |
113
+ | `draco.state` | Execution/event/checkpoint stores (`InMemory`, `Sqlite`, `Postgres`); retention | `draco-harness[postgres]` |
114
+ | `draco.observability`| `Tracer`, redaction, JSONL and OpenTelemetry exporters | `draco-harness[otel]` |
115
+ | `draco.plugins` | Service registry, plugin host, input/output guardrails, rate limiting | |
116
+ | `draco.adapters` | Translation to external components (`model_provider`, `providers`, `retrieval`, `ingestion`, `langgraph`) | see below |
117
+
118
+ *Dependency direction is enforced by tests: layers only import downward, and no Draco module imports application code.*
119
+
120
+ ## ⚙️ Installation
121
+ The package is named **`draco-harness`**; you still `import draco`. Once a release is on PyPI:
122
+ ```bash
123
+ pip install draco-harness # native framework (pydantic only)
124
+ pip install "draco-harness[agents,providers]"
125
+ ```
126
+ From a clone, for development *(`uv pip` is recommended, but standard `pip` works identically)*:
127
+ ```bash
128
+ uv pip install -e . # Native framework
129
+ uv pip install -e ".[agents]" # LangGraph adapter
130
+ uv pip install -e ".[providers]" # OpenAI-compatible / Anthropic model providers
131
+ uv pip install -e ".[postgres]" # PostgreSQL state store
132
+ uv pip install -e ".[crypto]" # Encryption at rest
133
+ uv pip install -e ".[mcp]" # MCP tools
134
+ uv pip install -e ".[otel]" # OpenTelemetry exporter
135
+ uv pip install -e ".[dev]" # pytest, ruff, mypy
136
+ ```
137
+
138
+ ## 🔒 Security Model
139
+ Your application authenticates the caller and hands Draco an `Identity(subject, tenant_id, roles)`.
140
+ - User and tenant come from that identity. Child executions inherit it.
141
+ - Nothing in input, tool arguments or metadata can override it.
142
+ - Protected operations pass through an `Authorizer` before any side effect, and every decision is audited.
143
+ - Tenant isolation covers resources, idempotency keys, resume and cancel.
144
+
145
+ 👉 *Full details: [docs/api-guide.md#security](docs/api-guide.md)*
146
+
147
+ ## 🔭 Observability & Persistence
148
+ - **Observability:** Every lifecycle step emits an event. The `Tracer` redacts secrets and pseudonymises IDs before storing or exporting. A failing telemetry handler never breaks a run.
149
+ - **Persistence:** `Harness(store=SqliteStore(path))` persists executions, redacted events and `step()` checkpoints. `resume(execution_id)` re-runs under the same ID.
150
+ - **Retention:** Purges old finished executions and never touches running or waiting ones. Encryption at rest (`FernetCipher`) covers input, output, error, event and step data.
151
+
152
+ ## 🧪 Examples
153
+ Run via `PYTHONPATH=src:. python -m examples.<name>`. They also run as tests.
154
+
155
+ | Example | Description |
156
+ |---|---|
157
+ | `a_simple` | Native workload, trace, persisted status |
158
+ | `c_multi_agent` | Agent registry, capability routing, handoffs |
159
+ | `d_tool` | Native tool, permissions, audit |
160
+ | `e_recovery` | Steps, failure, resume |
161
+ | `f_plugin` | Plugin with a service and hooks |
162
+ | `g_secure_tenants`| Identity, tenant isolation, role grants |
163
+ | `h_langgraph` | LangGraph graph through the adapter, interrupt and resume |
164
+
165
+ A RAG example over a real retrieval service lives in draco-rag (`examples/b_rag.py`).
166
+
167
+ ---
168
+
169
+ ## ⚠️ Known Limitations
170
+ - No authentication provider ships with Draco; you supply the `Identity`.
171
+ - The rate limiter and the tracer's in-memory trace are per process.
172
+ - Prompt-injection detection (`draco.tools.safety`) is a heuristic.
173
+ - **History rewritten (2026-11-27):** runtime data and personal documents that were committed earlier were removed from every branch. Clones and forks made before that date still hold the old history, and GitHub may still serve old commits through closed pull requests. Details: [docs/HISTORY_PURGE.md](docs/HISTORY_PURGE.md). To check a clone, run `scripts/check_history_exposure.sh`.
174
+
175
+ ## 🗺️ Roadmap
176
+ Planned work, kept separate from what is implemented: [docs/architecture/roadmap.md](docs/architecture/roadmap.md).
177
+
178
+ ---
179
+
180
+ ## 🤝 Contributing, Security & License
181
+ Contributions are welcome! Start with [CONTRIBUTING.md](CONTRIBUTING.md) for setup, CI checks, code and test standards, and pull request guidelines.
182
+ Questions and ideas go to [Discussions](https://github.com/AmartyaRanjan/Draco/discussions); see [SUPPORT.md](SUPPORT.md). Please read the [Code of Conduct](CODE_OF_CONDUCT.md).
183
+
184
+ 🚨 **Found a vulnerability?** Do not open a public issue. Follow [SECURITY.md](SECURITY.md).
185
+
186
+ **Quick development loop:**
187
+ ```bash
188
+ uv pip install -e ".[dev,providers]"
189
+ pytest tests/draco
190
+ ruff check src tests/draco examples
191
+ mypy src/draco
192
+ ```
193
+
194
+ Licensed under the [MIT License](LICENSE).
@@ -0,0 +1,143 @@
1
+ # 🐉 Draco
2
+
3
+ > An execution harness for RAG and agent systems.
4
+
5
+ [![CI](https://github.com/AmartyaRanjan/Draco/actions/workflows/ci.yml/badge.svg)](https://github.com/AmartyaRanjan/Draco/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
+ ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)
8
+ ![Status: alpha](https://img.shields.io/badge/status-alpha-orange)
9
+
10
+ [📖 Documentation](docs/README.md) · [🤝 Contributing](CONTRIBUTING.md) · [🛡️ Security](SECURITY.md) · [🗺️ Roadmap](docs/architecture/roadmap.md) · [📜 Changelog](docs/DRACO_CHANGELOG.md)
11
+
12
+ ---
13
+
14
+ ## 🏗️ Overview
15
+
16
+ Draco is a lightweight Python package that runs any async workload under one lifecycle. Its only hard dependency is `pydantic`. It provides:
17
+ - **Access control:** trusted identity, role-based authorization and default-deny tool policies.
18
+ - **Limits:** budgets, rate limits and deadlines.
19
+ - **Reliability:** idempotency and resumable steps.
20
+ - **Tracing:** redacted traces.
21
+ - **Durable state:** in-memory, SQLite or PostgreSQL.
22
+
23
+ It includes an agent registry and router, and a guarded tool runtime for native tools and, optionally, MCP tools. It also ships adapters for LangGraph, OpenAI-compatible providers and Anthropic.
24
+
25
+ > 🧩 **Built on Draco:** [draco-rag](https://github.com/AmartyaRanjan/draco-rag) is a FastAPI RAG and agent service that runs every chat, agent and resume request as a Draco workload. It started out in this repository as the starter app and now lives on its own.
26
+
27
+ ---
28
+
29
+ ## 🛠️ The Contract
30
+
31
+ ```python
32
+ Workload = Callable[[ExecutionContext, Any], Awaitable[Any]]
33
+ ```
34
+ Anything matching this shape can be registered with the `Harness`:
35
+
36
+ ```python
37
+ import asyncio
38
+ from draco import Harness, Identity
39
+
40
+ async def greeter(ctx, name):
41
+ return f"hello {name}"
42
+
43
+ async def main():
44
+ h = Harness()
45
+ h.register("greeter", greeter)
46
+ r = await h.run("greeter", "world", identity=Identity("alice", "acme"))
47
+ print(r.status, r.output, r.execution_id) # Status.completed hello world <id>
48
+
49
+ asyncio.run(main())
50
+ ```
51
+ `run()` always returns an `ExecutionResult` (`completed` | `failed` | `cancelled` | `timeout` | `budget_exhausted` | `handoff` | `waiting`). Failures are never reported as success; `result.raise_for_status()` re-raises them as typed `DracoError`.
52
+
53
+ ## 🏛️ Architecture Layers
54
+
55
+ | Package | Responsibility | Dependencies |
56
+ |---|---|---|
57
+ | `draco.core` | `ExecutionContext`, `Identity`, `Policy`, budgets, results, typed errors, events | `pydantic` |
58
+ | `draco.harness` | Lifecycle: identity, auth, guardrails, execution, deadlines, persistence, `resume()` | |
59
+ | `draco.agents` | `AgentRegistry`, `Router`, handoffs, delegation, loop/depth limits | |
60
+ | `draco.tools` | `Tool`, `ToolRegistry`, `ToolRuntime` (policy, retries, untrusted output), MCP tools | `draco-harness[mcp]` |
61
+ | `draco.security` | `Authorizer`, audit events, `Secret`, `FernetCipher` (encryption at rest) | `draco-harness[crypto]` |
62
+ | `draco.state` | Execution/event/checkpoint stores (`InMemory`, `Sqlite`, `Postgres`); retention | `draco-harness[postgres]` |
63
+ | `draco.observability`| `Tracer`, redaction, JSONL and OpenTelemetry exporters | `draco-harness[otel]` |
64
+ | `draco.plugins` | Service registry, plugin host, input/output guardrails, rate limiting | |
65
+ | `draco.adapters` | Translation to external components (`model_provider`, `providers`, `retrieval`, `ingestion`, `langgraph`) | see below |
66
+
67
+ *Dependency direction is enforced by tests: layers only import downward, and no Draco module imports application code.*
68
+
69
+ ## ⚙️ Installation
70
+ The package is named **`draco-harness`**; you still `import draco`. Once a release is on PyPI:
71
+ ```bash
72
+ pip install draco-harness # native framework (pydantic only)
73
+ pip install "draco-harness[agents,providers]"
74
+ ```
75
+ From a clone, for development *(`uv pip` is recommended, but standard `pip` works identically)*:
76
+ ```bash
77
+ uv pip install -e . # Native framework
78
+ uv pip install -e ".[agents]" # LangGraph adapter
79
+ uv pip install -e ".[providers]" # OpenAI-compatible / Anthropic model providers
80
+ uv pip install -e ".[postgres]" # PostgreSQL state store
81
+ uv pip install -e ".[crypto]" # Encryption at rest
82
+ uv pip install -e ".[mcp]" # MCP tools
83
+ uv pip install -e ".[otel]" # OpenTelemetry exporter
84
+ uv pip install -e ".[dev]" # pytest, ruff, mypy
85
+ ```
86
+
87
+ ## 🔒 Security Model
88
+ Your application authenticates the caller and hands Draco an `Identity(subject, tenant_id, roles)`.
89
+ - User and tenant come from that identity. Child executions inherit it.
90
+ - Nothing in input, tool arguments or metadata can override it.
91
+ - Protected operations pass through an `Authorizer` before any side effect, and every decision is audited.
92
+ - Tenant isolation covers resources, idempotency keys, resume and cancel.
93
+
94
+ 👉 *Full details: [docs/api-guide.md#security](docs/api-guide.md)*
95
+
96
+ ## 🔭 Observability & Persistence
97
+ - **Observability:** Every lifecycle step emits an event. The `Tracer` redacts secrets and pseudonymises IDs before storing or exporting. A failing telemetry handler never breaks a run.
98
+ - **Persistence:** `Harness(store=SqliteStore(path))` persists executions, redacted events and `step()` checkpoints. `resume(execution_id)` re-runs under the same ID.
99
+ - **Retention:** Purges old finished executions and never touches running or waiting ones. Encryption at rest (`FernetCipher`) covers input, output, error, event and step data.
100
+
101
+ ## 🧪 Examples
102
+ Run via `PYTHONPATH=src:. python -m examples.<name>`. They also run as tests.
103
+
104
+ | Example | Description |
105
+ |---|---|
106
+ | `a_simple` | Native workload, trace, persisted status |
107
+ | `c_multi_agent` | Agent registry, capability routing, handoffs |
108
+ | `d_tool` | Native tool, permissions, audit |
109
+ | `e_recovery` | Steps, failure, resume |
110
+ | `f_plugin` | Plugin with a service and hooks |
111
+ | `g_secure_tenants`| Identity, tenant isolation, role grants |
112
+ | `h_langgraph` | LangGraph graph through the adapter, interrupt and resume |
113
+
114
+ A RAG example over a real retrieval service lives in draco-rag (`examples/b_rag.py`).
115
+
116
+ ---
117
+
118
+ ## ⚠️ Known Limitations
119
+ - No authentication provider ships with Draco; you supply the `Identity`.
120
+ - The rate limiter and the tracer's in-memory trace are per process.
121
+ - Prompt-injection detection (`draco.tools.safety`) is a heuristic.
122
+ - **History rewritten (2026-11-27):** runtime data and personal documents that were committed earlier were removed from every branch. Clones and forks made before that date still hold the old history, and GitHub may still serve old commits through closed pull requests. Details: [docs/HISTORY_PURGE.md](docs/HISTORY_PURGE.md). To check a clone, run `scripts/check_history_exposure.sh`.
123
+
124
+ ## 🗺️ Roadmap
125
+ Planned work, kept separate from what is implemented: [docs/architecture/roadmap.md](docs/architecture/roadmap.md).
126
+
127
+ ---
128
+
129
+ ## 🤝 Contributing, Security & License
130
+ Contributions are welcome! Start with [CONTRIBUTING.md](CONTRIBUTING.md) for setup, CI checks, code and test standards, and pull request guidelines.
131
+ Questions and ideas go to [Discussions](https://github.com/AmartyaRanjan/Draco/discussions); see [SUPPORT.md](SUPPORT.md). Please read the [Code of Conduct](CODE_OF_CONDUCT.md).
132
+
133
+ 🚨 **Found a vulnerability?** Do not open a public issue. Follow [SECURITY.md](SECURITY.md).
134
+
135
+ **Quick development loop:**
136
+ ```bash
137
+ uv pip install -e ".[dev,providers]"
138
+ pytest tests/draco
139
+ ruff check src tests/draco examples
140
+ mypy src/draco
141
+ ```
142
+
143
+ Licensed under the [MIT License](LICENSE).
@@ -0,0 +1,75 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"] # 77+ for the SPDX `license` expression and `license-files`
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "draco-harness"
7
+ version = "0.1.0"
8
+ description = "Embeddable agent runtime: harness, routing, tools, security, state and observability, with optional adapters"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Amartya Ranjan" }]
14
+ keywords = ["rag", "agents", "llm", "harness", "orchestration", "retrieval", "langgraph", "tool-use", "multi-tenant"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ "Typing :: Typed",
25
+ ]
26
+ # The native framework (core, harness, agents, routing, tools, security, state, observability) needs only
27
+ # pydantic. Everything else is an optional extra. Lower bounds are the oldest versions Draco supports.
28
+ dependencies = ["pydantic>=2.6"]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/AmartyaRanjan/Draco"
32
+ Documentation = "https://github.com/AmartyaRanjan/Draco/blob/main/docs/README.md"
33
+ Source = "https://github.com/AmartyaRanjan/Draco"
34
+ Issues = "https://github.com/AmartyaRanjan/Draco/issues"
35
+ Changelog = "https://github.com/AmartyaRanjan/Draco/blob/main/docs/DRACO_CHANGELOG.md"
36
+ "Security Policy" = "https://github.com/AmartyaRanjan/Draco/blob/main/SECURITY.md"
37
+
38
+ [project.optional-dependencies]
39
+ agents = ["langgraph>=1.0", "langchain-core", "langgraph-checkpoint-sqlite>=2.0"] # draco.adapters.langgraph
40
+ providers = ["httpx>=0.27"] # draco.adapters.providers (OpenAI-compatible, Anthropic)
41
+ mcp = ["mcp>=1.0"]
42
+ postgres = ["psycopg[binary]>=3.1"] # draco.state.postgres.PostgresStore
43
+ crypto = ["cryptography>=42"] # draco.security.crypto.FernetCipher (encryption at rest)
44
+ otel = ["opentelemetry-api", "opentelemetry-sdk"]
45
+ dev = ["pytest>=8", "ruff", "mypy", "pip-audit"]
46
+ docs = ["mkdocs>=1.6", "mkdocs-material>=9.5"] # mkdocs serve / mkdocs build --strict
47
+
48
+ [tool.setuptools.packages.find]
49
+ where = ["src"]
50
+ include = ["draco*"]
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ pythonpath = ["src", "."]
55
+
56
+ [tool.ruff]
57
+ line-length = 110
58
+ target-version = "py311"
59
+ src = ["src", "tests"]
60
+
61
+ [tool.ruff.lint]
62
+ select = ["E", "F", "I", "B", "UP"]
63
+ ignore = ["E501"]
64
+
65
+ [tool.ruff.lint.per-file-ignores]
66
+ "**/__init__.py" = ["F401", "F403"] # re-export modules
67
+ "tests/**" = ["E701", "E702", "E731"]
68
+ "examples/**" = ["E701", "E702", "E731"]
69
+
70
+ [tool.mypy]
71
+ python_version = "3.11"
72
+ files = ["src/draco"]
73
+ ignore_missing_imports = true
74
+ warn_unused_ignores = true
75
+ check_untyped_defs = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ """Draco: execution harness and extension layer for RAG and agentic apps."""
2
+ from draco.core import (
3
+ BudgetLimits,
4
+ DracoError,
5
+ DracoSettings,
6
+ ExecutionContext,
7
+ ExecutionResult,
8
+ Handoff,
9
+ Identity,
10
+ Policy,
11
+ Status,
12
+ Waiting,
13
+ )
14
+ from draco.harness import Harness, call_model, call_with_retry, step
15
+
16
+ __version__ = "0.1.0"
17
+ __all__ = ["BudgetLimits", "DracoError", "DracoSettings", "ExecutionContext", "ExecutionResult", "Handoff", "Harness", "Identity",
18
+ "Policy", "Status", "Waiting", "call_model", "call_with_retry", "step"]
@@ -0,0 +1,6 @@
1
+ """Adapters translate external components into Draco contracts.
2
+
3
+ Each adapter is its own module and pulls in its optional dependency only when imported:
4
+ `retrieval`, `ingestion`, `model_provider`, `providers`, `langgraph`, `langgraph_checkpoint`.
5
+ Application-specific adapters live with the application (for example `app.draco_adapters` in draco-rag).
6
+ """
@@ -0,0 +1,35 @@
1
+ """Generic ingestion workload: the harness runs whatever callable the application injects. Parsing,
2
+ chunking, embedding and storage stay in that callable; nothing here knows about them."""
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import inspect
7
+ from collections.abc import Callable
8
+ from typing import Any
9
+
10
+ from draco.core.context import ExecutionContext
11
+ from draco.core.errors import ContractError
12
+ from draco.core.protocols import Workload
13
+ from draco.security.audit import authorize
14
+ from draco.security.authorization import Resource
15
+
16
+
17
+ def ingest_workload(ingest: Callable[..., Any], *, resource_for: Callable[[str], Resource] | None = None) -> Workload:
18
+ """input {'document_id': str, 'file_path': str}. `ingest(document_id, file_path)` may be sync (run in a
19
+ thread) or async. With `resource_for`, `document.ingest` is authorized on the target document before the
20
+ callable runs. Re-running is only safe if `ingest` is idempotent (e.g. deterministic chunk ids)."""
21
+ async def run(ctx: ExecutionContext, inp: Any) -> dict[str, Any]:
22
+ if not isinstance(inp, dict) or not {"document_id", "file_path"} <= inp.keys():
23
+ raise ContractError("input must contain document_id and file_path")
24
+ ctx.check()
25
+ doc = str(inp["document_id"])
26
+ if resource_for is not None:
27
+ await authorize(ctx, "document.ingest", resource_for(doc))
28
+ elif ctx.identity is not None:
29
+ await authorize(ctx, "document.ingest", Resource("document", doc, tenant_id=ctx.tenant_id))
30
+ if inspect.iscoroutinefunction(ingest):
31
+ await ingest(doc, inp["file_path"])
32
+ else:
33
+ await asyncio.to_thread(ingest, doc, inp["file_path"])
34
+ return {"document_id": doc, "status": "processed"}
35
+ return run
@@ -0,0 +1,57 @@
1
+ """Run any compiled LangGraph graph as a Draco workload. LangGraph stays the graph engine; install with
2
+ `pip install draco-harness[agents]` (this module itself imports nothing from langgraph).
3
+
4
+ Semantics:
5
+ - thread id: the Draco execution id, so a checkpointer's state is keyed to the execution. `Harness.resume`
6
+ keeps the execution id, so a resumed run continues the same LangGraph thread.
7
+ - identity: tenant, user, session and correlation ids are passed as run metadata (for tracing only; they
8
+ are never read back from graph state).
9
+ - recursion: `recursion_limit` bounds graph supersteps; exceeding it is reported as `BudgetExhausted`.
10
+ - interrupts: a result containing LangGraph's `__interrupt__` is returned as `Waiting`; continue with
11
+ `harness.resume(id, input=Command(resume=...))`.
12
+ - cancellation/deadline: enforced by the harness around the `ainvoke` task (cooperative at awaits).
13
+ - budgets: model calls made *inside* the graph are only counted if the graph's nodes call
14
+ `draco.harness.call_model`; the adapter cannot see them otherwise."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from collections.abc import Callable
19
+ from typing import Any
20
+
21
+ from draco.adapters.langgraph_checkpoint import checkpoint_config
22
+ from draco.core.context import ExecutionContext
23
+ from draco.core.errors import BudgetExhausted
24
+ from draco.core.protocols import Workload
25
+ from draco.core.results import Waiting
26
+
27
+
28
+ def graph_workload(
29
+ graph: Any,
30
+ *,
31
+ to_state: Callable[[Any], Any] = lambda x: x,
32
+ from_state: Callable[[Any], Any] = lambda s: s,
33
+ recursion_limit: int = 25,
34
+ ) -> Workload:
35
+ """`graph` is a compiled graph with `ainvoke`."""
36
+
37
+ async def run(ctx: ExecutionContext, inp: Any) -> Any:
38
+ ctx.check()
39
+ cfg = checkpoint_config(
40
+ ctx.execution_id,
41
+ tenant_id=ctx.tenant_id,
42
+ user_id=ctx.user_id,
43
+ session_id=ctx.session_id,
44
+ correlation_id=ctx.correlation_id,
45
+ recursion_limit=recursion_limit,
46
+ )
47
+ try:
48
+ out = await graph.ainvoke(to_state(inp), cfg)
49
+ except Exception as exc:
50
+ if type(exc).__name__ == "GraphRecursionError":
51
+ raise BudgetExhausted("graph_steps", recursion_limit) from exc
52
+ raise
53
+ if isinstance(out, dict) and out.get("__interrupt__"):
54
+ return Waiting("graph interrupted", [getattr(i, "value", i) for i in out["__interrupt__"]])
55
+ return from_state(out)
56
+
57
+ return run