Build a multi-model, multi-agent contract assistant on Microsoft Foundry β grounded with Foundry IQ, traced and evaluated, exposed as an MCP server, and published to Microsoft 365 Copilot & Teams.
A 4.5-hour microhack Β· 5 challenges (+ optional bonus) Β· code-first (Python) Β· runs locally in VS Code.
Contract lifecycle management is where enterprises quietly lose time and money: slow intake, inconsistent clause review, and missed renewals. In this microhack you'll transform CLM into an AI-native, enterprise-ready system on Microsoft Foundry β turning a manual, weeks-long process into a grounded, agentic workflow with a human always in the loop.
The build uniquely combines four things: a multi-model GPT fleet β orchestration and specialist drafting share GPT-5.4, clause-analysis runs on GPT-5.6 Sol, and renewal tracking runs on GPT-5.4-nano, all inside a single Foundry project; grounded retrieval with Foundry IQ over your own contract corpus so every answer is cited; tools and an MCP server that expose the workflow to Microsoft 365 Copilot, Teams, and any MCP-compatible client; and the full GenAIOps lifecycle β OpenTelemetry tracing to Application Insights, evaluation scorecards with a quality gate, and (bonus) AI red-teaming plus Content Safety guardrails. From grounded single-agent drafting through multi-agent orchestration to an observable, governed, published assistant, you'll master the full stack of enterprise agentic AI β and ship something your legal and procurement teams would actually use.
This microhack uses a fictitious multinational, Contoso Global, but the scenario applies to any enterprise that manages contracts at scale. The points below illustrate the conceptual scenario.
βΆ Contoso signs hundreds of contracts a month β NDAs, MSAs, procurement and partnership agreements β each moving through the same lifecycle: intake β drafting β clause review β approval β obligation tracking β renewal.
β· The business runs on two numbers: cycle time and renewal capture. Today that's a ~17-day turnaround and ~11% of auto-renewals missed β and every missed renewal is lost revenue or unwanted lock-in.
βΈ Reviewing a counterparty draft means manually comparing every clause to the enterprise Standard Clause Library β slow, inconsistent between reviewers, and impossible to scale.
βΉ Contracts and their obligations are scattered across SharePoint, email, and legacy systems β there's no single source of truth for status, owners, and key dates.
βΊ Legal and Procurement can't hand this to a black box: human sign-off, citations, and a full audit trail are non-negotiable. Trust, traceability, and safety are requirements, not extras.
The process is complex and coordination-heavy. Common challenges include:
- Drafting consistently from approved templates instead of ad-hoc copy-paste.
- Risk-scoring counterparty clauses against the standard β quickly and repeatably.
- Answering "what's our standard position on X?" with cited sources, not tribal knowledge.
- Keeping a human in the loop on every finalization, with a reviewable trail.
- Never missing a renewal or obligation date across thousands of live contracts.
Agents help by coordinating these steps β drafting, reviewing, answering, tracking, and alerting β while keeping a person in control. You'll build an Agentic CLM system: an Orchestrator coordinating grounded specialist agents, all inside one Microsoft Foundry project with human sign-off and full tracing.
π€ Persona β a Legal / Procurement contract manager at Contoso Global, drowning in intake, clause review, and renewals. They live in Microsoft 365 Copilot & Teams β not in a new tool. The whole system meets them there.
Here's a single day in that manager's life once the Agentic CLM assistant is live. Each step maps directly to what you build in the challenges β follow the user-journey diagram alongside this table.
| # | What the manager does | What happens under the hood | Foundry capability | Built in |
|---|---|---|---|---|
| 1 Β· Request a draft | "Draft a mutual NDA with Acme, 2-yr term." | Intake & Drafting agent (GPT-5.4, shared with the Orchestrator) drafts from an approved template | Grounded agent + tools | C2 |
| 2 Β· Check their draft | Uploads Acme's counter-draft MSA | Clause & Risk agent (GPT-5.6 Sol) scores every clause against the Standard Clause Library and flags deviations | Specialist agent + orchestration | C4 |
| 3 Β· Ask, with citations | "What's our standard indemnity cap?" | Foundry IQ answers over the Contoso corpus β with sources | Agentic retrieval (Foundry IQ) | C2 |
| 4 Β· Review & sign off | Reads flags + citations, edits, approves | Human-in-the-loop β nothing is finalized without sign-off | HITL + guardrails | C2 Β· C4 |
| 5 Β· Track obligations | Reviews upcoming renewals | Obligation & Renewal agent (GPT-5.4-nano) reads contract status & upcoming renewals via function tools β Azure SQL (seed-data fallback) | Function tool / MCP server | C4 Β· C5 |
π Under the hood, every step runs in one Microsoft Foundry project β traced (Application Insights), scored by evaluations (C3), and guarded by Content Safety (bonus C6). That observability + safety layer is what turns a demo into something legal and procurement teams would actually trust.
π Prefer a visual? The user-journey diagram above is saved in
images/diagrams/ as user-journey.png, alongside the
finalized architecture.png.
The diagram below shows the end-to-end architecture you'll build β a layered system with the contract
manager on top, the agent fleet and grounding in a single Microsoft Foundry project in the middle,
and observability underneath. The finalized diagram lives in
images/diagrams/.
βΆ Consumption plane β where the manager already works. At the top, the contract manager interacts through Microsoft 365 Copilot & Teams (teal). There's no new app to learn: the assistant meets users in the tools they use daily, and the two-way arrow to the Orchestrator carries requests down and grounded answers back.
β· The Microsoft Foundry project (navy) β one governed home for every agent and model. Everything runs inside a single Foundry project: shared identity (Entra), model deployments, tool connections, tracing, and safety. Crucially, three GPT model deployments support four agent roles here β no second platform to operate.
βΈ Orchestrator (GPT-5.4) β the front door. It receives each request, decides which specialist to call, hands off the right context, and composes the final answer. GPT-5.4 is chosen for fast, deterministic routing and tool/hand-off calls rather than long-form generation.
βΉ Specialist agents β each matched to its task and its model. The Orchestrator delegates to three grounded specialists: Intake & Drafting shares GPT-5.4 with the Orchestrator for high-fidelity drafting while Clause & Risk runs on GPT-5.6 Sol for structured clause comparison; Obligation & Renewal runs on the cheaper GPT-5.4-nano (blue) for high-frequency date and obligation extraction.
βΊ Grounding & tools (blue) β how agents stay factual and act on the world. Foundry IQ (over
Azure AI Search) provides agentic retrieval so drafting and clause agents answer with citations
from the contract corpus β the original PDFs live in a SharePoint document library that a SharePoint
Online indexer crawls into the index; Azure SQL is the system of record for contract status, read/written by
the renewal agent through a function tool; an optional Bing web search tool gives the Clause & Risk
agent public web grounding for counterparty due-diligence (off by default); and the MCP server
(draft_contract Β· analyze_contract) re-exposes the whole workflow as Model Context Protocol tools
any MCP client β including M365 Copilot β can call. The Orchestrator can itself be that client
(src/orchestrator_mcp.py), consuming the workflow over MCP instead of in-process.
β» Observability & governance (gray) β what turns a demo into production. Every run streams OpenTelemetry traces to Application Insights, while Evaluations + Content Safety score answer quality and enforce guardrails. The dashed lines are telemetry (traces, scorecards) flowing out of the Foundry project β the layer that makes agent behavior debuggable, measurable, and safe.
π¨ Legend: π¦ blue = GPT agents Β· πͺ purple = Intake & Drafting Β· π§ orange = tools / MCP Β· π© green = data / grounding Β· β¬ gray = governance Β· dashed grey = telemetry Β· dashed red = guardrails. The finalized architecture image β plus the end-to-end user journey (Excalidraw) β lives in
images/diagrams/.
Mermaid source
flowchart TB
user["π€ Contract Manager<br/>Microsoft 365 Copilot / Teams"]
hitl["π Human-in-the-loop<br/>review & sign-off"]
user <--> hitl
subgraph Foundry["Microsoft Foundry project"]
subgraph Agents["Agent layer"]
orch["Orchestrator Agent"]
intake["Intake & Drafting"]
clause["Clause & Risk"]
renew["Obligation & Renewal"]
orch --> intake
orch --> clause
orch --> renew
end
subgraph Farm["LLM farm Β· model deployments"]
gpt54["GPT-5.4<br/>OpenAI Β· GlobalStandard"]
gpt56sol["GPT-5.6 Sol<br/>OpenAI Β· GlobalStandard"]
gpt5mini["GPT-5.4-nano<br/>OpenAI Β· GlobalStandard"]
end
orch -->|runs on| gpt54
intake -->|shares| gpt54
clause -->|runs on| gpt56sol
renew -->|runs on| gpt5mini
end
hitl <--> orch
subgraph Ground["Grounding & tools"]
sources[("Content corpus Β· SharePoint<br/>Clause Library Β· Templates")]
iq[("Foundry IQ<br/>Azure AI Search")]
sql[("Azure SQL<br/>contract status")]
bing["Bing web search<br/>(optional Β· off by default)"]
mcp["MCP server<br/>draft_contract Β· analyze_contract"]
end
sources -->|SharePoint indexer| iq
intake --> iq
clause --> iq
clause -. "web grounding" .-> bing
renew --> sql
orch --> mcp
user -. "MCP tools" .-> mcp
subgraph Sec["Platform & security"]
entra["π Microsoft Entra ID<br/>identity Β· RBAC Β· residency"]
safety["π‘οΈ Azure AI Content Safety<br/>inline guardrail"]
end
entra -. identity .-> Foundry
safety <-. guardrail .-> orch
subgraph Obs["Observability & governance"]
ai["App Insights Β· OpenTelemetry"]
eval["Evaluations Β· red-teaming Β· quality gate"]
end
Foundry -.traces.-> ai
Foundry -.scorecard.-> eval
The fleet uses four agent roles across three distinct GPT deployments in one Foundry project: the Orchestrator and Intake & Drafting share GPT-5.4, Clause & Risk uses GPT-5.6 Sol, and Obligation & Renewal uses GPT-5.4-nano. The platform remains model-agnostic β teams can swap GPT deployments through configuration without changing the agent or tool code.
| Agent | Model | Why this model |
|---|---|---|
| Orchestrator | GPT-5.4 | Fast, deterministic routing + tool/hand-off calls |
| Intake & Drafting | GPT-5.4 | High-fidelity, template-grounded drafting; shares the Orchestrator deployment |
| Clause & Risk | GPT-5.6 Sol | Structured clause comparison + nuanced risk rationale |
| Obligation & Renewal | GPT-5.4-nano | Cheap, high-frequency structured extraction + alerts |
By participating in this hackathon, you will learn how to:
- Build grounded, tool-using agents with the Microsoft Agent Framework β author agents with instructions, tools, and safety on Foundry as the chat-client provider, and run the same patterns across multiple GPT deployments from the Foundry model catalog. (Challenges 2, 4)
- Ground answers with Foundry IQ β connect a knowledge source over your contract corpus and use agentic retrieval on Azure AI Search so every answer is cited, not hallucinated. (Challenge 2)
- Connect tools and expose an MCP server β add a function tool that reads contract status from Azure SQL, then publish the workflow as a Model Context Protocol server any MCP client can call. (Challenge 4)
- Orchestrate a multi-agent system with the Microsoft Agent Framework agent-as-tool pattern β an Orchestrator delegating to specialist drafting, clause-risk, and renewal agents via
agent.as_tool(...)(reinforced by this multi-agent training module). (Challenge 4) - Practice GenAIOps β tracing & observability β emit OpenTelemetry traces to Application Insights, then run evaluations to score quality, add a quality gate, and run a flagship-vs-mini bake-off. (Challenge 3)
- Publish to Microsoft 365 Copilot & Teams β surface the assistant where contract managers already work. (Challenge 5)
- Apply Responsible AI (bonus) β red-team the agent, add Azure AI Content Safety / PII guardrails, and gate releases on a quality + safety check in CI. (Challenge 6)
Every challenge adds one capability to the same Foundry project β read top to bottom, the six challenges are a single story:
- Ground it (C1βC2) β deploy Foundry, seed the Contoso corpus, and build an agent that answers from the documents, with citations β not from model memory.
- Prove it's good (C3) β trace every run and score it against a labelled set, with a quality gate that blocks a bad build.
- Orchestrate a team (C4) β add a second specialist and an Orchestrator that routes to both, then expose the whole workflow as a reusable MCP server.
- Deliver it (C5) β publish the Orchestrator to M365 Copilot & Teams so legal uses it where they already work.
- Make it safe (C6, bonus) β red-team it, add Content Safety, and gate CI so a risky change can never ship.
In one line: a grounded assistant β proven trustworthy β scaled into a team β delivered to users β hardened for production. Each challenge closes with a π How this fits note tying its piece back to this arc.
| # | Challenge | Focus | Duration |
|---|---|---|---|
| 1 | Resource deployment Β· local venv setup Β· .env Β· corpus seeding |
Setup | 30 min |
| 2 | Intake & Drafting agent + Foundry IQ + tools | Grounding Β· tools Β· guardrails | 60 min |
| 3 | Observability, tracing & evaluation | Tracing Β· eval | 60 min |
| 4 | Clause & Risk agent + Orchestrator + MCP server | Orchestration Β· MCP | 55 min |
| 5 | Publish to M365 Copilot & Teams | Publish | 30 min |
| 6 π§ͺ | Bonus: Safety, Red-Teaming & Continuous Eval | Responsible AI Β· CI gate | optional |
| Time | Activity |
|---|---|
| 09:00 β 10:00 | Tech Talk |
| 10:00 β 12:30 | Team hacking β Challenges 1, 2, 3 |
| 12:30 β 13:30 | Lunch break |
| 13:30 β 15:30 | Team hacking β Challenges 4, 5 |
| 15:30 β 16:00 | Final discussion / wrap up |
π§ͺ Bonus Challenge 6 (Safety, Red-Teaming & Continuous Eval) is optional β for teams who finish early. It doesn't fit inside the 4.5h; tackle it if you have time or as follow-up.
π©βπ« Running this event? See the Coach & Facilitator Guide β before-the-day checklist, run-of-show, per-challenge blockers & hints, and a reset/recovery playbook.
- An Azure subscription with rights to create a Foundry project and deploy GPT models (confirm availability in your target region via the model catalog).
- GitHub account (to clone the repo).
- Python 3.11+, Git, the Azure CLI (
az), and the Azure Developer CLI (azd) installed locally. Basic Python knowledge; a virtual environment keeps the pinned deps isolated. - For Challenge 5: a Microsoft 365 tenant where you can sideload a Teams app (or a coach-provided one).
- Clone this repo and open it in VS Code (no fork needed β the optional Challenge 6 CI bonus is the only part that needs a fork). Create a virtual environment and install the dependencies:
python -m venv .venv source .venv/bin/activate # Windows (PowerShell): .venv\Scripts\Activate.ps1 python -m pip install --upgrade pip pip install -r src/requirements.txt
az login(andazd auth loginif you use theazd uppath)- Do Challenge 1 to deploy resources and seed the corpus β provision with
azd up(run fromsrc/; Bicep inlabautomation/infra/), thelabautomation/deployscript, or the one-click Deploy to Azure button (infra/azuredeploy.json). The first two autofill your.env.- Seeding the corpus β default is Path B (Challenge 1 Β· Task 6): Path B (local-PDF) needs
no SharePoint and no admin consent, works in every tenant, and builds the
clm-corpusindex β blank theSHAREPOINT_*values in.envand runpython src/scripts/seed_corpus.py. Path A (real SharePoint corpus) is optional and needs tenant-admin rights; both build the identical index.
- Seeding the corpus β default is Path B (Challenge 1 Β· Task 6): Path B (local-PDF) needs
no SharePoint and no admin consent, works in every tenant, and builds the
- Work through Challenges 2 β 5.
.
βββ README.md # this file
βββ challenges/ # challenge-01 β¦ challenge-06 (one markdown brief per challenge)
βββ walkthrough/ # challenge-0N/solution-0N.md β reference solution per challenge
βββ src/ # all source code + build/config: agents/, clm_common/, mcp_server/, data/, scripts/ β¦
β βββ azure.yaml # azd config (points at ../labautomation/infra, write-.env hook) β run `cd src && azd up`
β βββ Dockerfile # Challenge 4 MCP server image (.dockerignore alongside; build context = src/)
β βββ requirements.txt # Python dependencies
β βββ data/ # CLM corpus (PDF contracts/templates/clauses/policies) + eval datasets
βββ labautomation/ # infra (Bicep) + deploy, seed corpus/SQL, write .env, smoke test
βββ images/ # rendered images + per-challenge screenshots + diagrams
βββ docs/ # coach guide, marketing
Generate images locally with
python src/scripts/make_banner.pyandmmdc -i src/scripts/architecture.mmd -o images/architecture.png -b white -s 3 -w 1600. Regenerate the Teams app icons withpython src/scripts/make_icons.py.
Each challenge README follows the same anatomy: π― Objective Β· π§ Context Β· β Tasks Β· βοΈ Success criteria Β· π οΈ Troubleshooting Β· π§ Reflection.
On "solutions": each challenge folder ships a complete, working reference implementation β there's no separate
solutions/folder. The challenge is to run it, understand why it works, and extend it, not to type it from a blank file. The code is the answer key.
Guardrail: the agents assist Legal & Procurement β they draft, analyze, and recommend, but they do not give legal advice and never execute a contract. A human always approves and signs.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.


