|
| 1 | +## 🧠 Agentic Human-In-The-Loop — Durable Workflows with Dapr (+ OpenAI, Gemini, Anthropic) |
| 2 | + |
| 3 | +This repo demonstrates a durable, agentic AI workflow for contract review built on Dapr Workflows and a simple FastAPI service. It ships three interchangeable implementations using different LLM providers: |
| 4 | + |
| 5 | +* `./anthropic/` — Anthropic Claude–based contract analyst |
| 6 | +* `./gemini/` — Google Gemini–based contract analyst |
| 7 | +* `./openai/` — OpenAI-based contract analyst |
| 8 | + |
| 9 | +Each example uses the same workflow shape: **analyze → decide → (optionally) wait for human approval → finalize → report**. The only difference is the LLM client and prompts used under the hood. |
| 10 | + |
| 11 | +Start in the provider folder you want (e.g., cd gemini) and follow that README. |
| 12 | + |
| 13 | +### ✨ What the Agentic Workflow Does |
| 14 | + |
| 15 | +* **LLM analysis**: Extract risks and summarize the contract. |
| 16 | +* **Decision**: If risk > threshold, propose amendments and pause for human approval. |
| 17 | +* **Durability**: The workflow persists state and can survive restarts and timeouts. |
| 18 | +* **Output**: Emit a structured JSON report for downstream systems. |
| 19 | + |
| 20 | + |
| 21 | +All three implementations share these semantics; you can swap providers without changing orchestration logic. |
| 22 | + |
| 23 | +### 🧩 Tech Highlights |
| 24 | + |
| 25 | +* **Dapr Workflows**: Durable execution, timers, retries, external event waiting. |
| 26 | +* **FastAPI**: Minimal HTTP surface for starting workflows and posting approvals. |
| 27 | + |
| 28 | +### 🛠 Prerequisites (All Providers) |
| 29 | + |
| 30 | +* Python 3.10+ |
| 31 | +* [Dapr and Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/) |
| 32 | +* Docker (for local Dapr dependencies) |
| 33 | +* Provider API key (one of): |
| 34 | + * **OpenAI**: OPENAI\_API\_KEY |
| 35 | + * **Gemini**: GEMINI\_API\_KEY |
| 36 | + * **Anthropic**: ANTHROPIC\_API\_KEY |
| 37 | + |
| 38 | +Each subfolder has its own requirements.txt and provider-specific notes. |
| 39 | + |
| 40 | +### 🚀 Quickstart |
| 41 | + |
| 42 | +Pick a provider folder and follow its README. The flow is generally: |
| 43 | + |
| 44 | +```bash |
| 45 | +# 1) Choose a provider implementation |
| 46 | +cd openai # or gemini / anthropic |
| 47 | + |
| 48 | +# 2) Install deps |
| 49 | +pip install -r requirements.txt |
| 50 | + |
| 51 | +# 3) Export your provider API key |
| 52 | +export OPENAI_API_KEY=... // or GEMINI_API_KEY or ANTHROPIC_API_KEY |
| 53 | + |
| 54 | +# 4) Run the FastAPI app with Dapr |
| 55 | +dapr run --app-id contract-review --app-port 8000 -- uvicorn app:app --reload |
| 56 | + |
| 57 | +# 5) Kick off a contract review (example payloads in each README) |
| 58 | +curl -X POST http://localhost:8000/review -H "Content-Type: application/json" -d '{ "...": "..." }' |
| 59 | + |
| 60 | +# 6) If required, approve later by posting to /approve/{instanceId} |
| 61 | + |
| 62 | +curl -X POST http://localhost:8000/approve/workflow-<CONTRACT-ID> -H "Content-Type: application/json" -d '{ |
| 63 | + "approved": true, |
| 64 | + "reviewer": "Alice", |
| 65 | + "notes": "Reviewed and approved." |
| 66 | +}' |
| 67 | +``` |
| 68 | + |
| 69 | +### 🔄 Choosing a Provider |
| 70 | + |
| 71 | +Start with the provider you already use in production or prefer for pricing/latency. |
| 72 | + |
| 73 | +The workflow contract (endpoints, payloads, and output JSON) is held constant across implementations to make A/B comparisons trivial. |
| 74 | + |
| 75 | +#### 🧪 Example Endpoints (common shape) |
| 76 | + |
| 77 | +* POST /review — Start a new workflow instance with a contract payload |
| 78 | +* POST /approve/{instanceId} — Resume a paused workflow with human approval |
| 79 | + |
| 80 | +See each provider's README for exact payloads and sample cURL commands. |
| 81 | + |
| 82 | +#### 🧱 Architecture (High-Level) |
| 83 | + |
| 84 | +```yaml |
| 85 | +[Client] ──HTTP──> [FastAPI + Dapr Workflow] |
| 86 | + │ |
| 87 | + ├─ Activity: LLM Analysis (OpenAI/Gemini/Anthropic) |
| 88 | + ├─ Timer/Wait: Human Approval (external event) |
| 89 | + └─ Activity: Finalize Report → JSON |
| 90 | +``` |
| 91 | +
|
| 92 | +* **Durability**: Dapr Workflow state persists in the configured state store. |
| 93 | +* **Resilience**: Retries and timers are handled by the workflow runtime. |
| 94 | +* **Extensibility**: Add tools (RAG, DB lookups, signature checks) as new activities. |
| 95 | + |
| 96 | +### 🧯 Troubleshooting |
| 97 | +
|
| 98 | +* Run dapr status to confirm the sidecar and default components are healthy. |
| 99 | +* If workflow doesn't resume, verify you're posting approval to the correct instance ID. |
| 100 | +* If the workflow doesn't kick off, make sure you're using a new instance ID in the /review request. |
| 101 | +* Check provider-specific rate limits or key scopes. |
| 102 | +* Inspect app logs (and Dapr sidecar logs) for activity failures and retries. |
| 103 | + |
| 104 | +### 📚 Related Docs |
| 105 | +-------------------------------- |
| 106 | +
|
| 107 | +* **Dapr Workflows**: [https://docs.dapr.io/developing-applications/building-blocks/workflow/](https://docs.dapr.io/developing-applications/building-blocks/workflow/) |
| 108 | +* **OpenAI Python SDK**: [https://platform.openai.com/docs/](https://platform.openai.com/docs/) |
| 109 | +* **Google Gemini**: [https://aistudio.google.com/](https://aistudio.google.com/) |
| 110 | +* **Anthropic Claude**: [https://docs.anthropic.com/](https://docs.anthropic.com/) |
| 111 | +
|
| 112 | +<br> |
| 113 | +Built with ❤️ using Dapr Workflows. Swap the model, keep the durability. |
0 commit comments