Databricks Apps · Agent architecture
Manufacturing
Procurement Agent
An AI advisor for a plastics manufacturer buying polyethylene resins — it decides buy or wait, how much, and from which supplier by combining internal data, live oil-market signals, an ML deal-quality model, and company policy.
jywu.jywu_mfg_agent · adb-984752964297111 (Azure)
The job
One question, four kinds of evidence
A procurement lead gets a supplier quote and has minutes to judge it. The agent answers the real question they'd ask a team of analysts:
“Should I buy 200 tons of HDPE at $1,300/ton right now?”
Do we need it?
On-hand inventory, safety stock, days of supply, upcoming demand.
Is the timing right?
Crude-oil price and trend — resin tracks oil with a lag.
Is it a good price?
An ML model scores the deal against past outcomes.
Is it allowed?
Approval thresholds, preferred suppliers, contract terms.
At a glance
How a question flows through the system
The agent
A thin, resilient orchestrator
Framework
OpenAI Agents SDK Runner inside MLflow agent_server (@invoke/@stream), served on Databricks Apps.
LLM
databricks-claude-sonnet-4-5 via direct FM serving. An env flag switches to the AI Gateway on workspaces where the FM path is disabled.
Instructions
A procurement-advisor prompt that folds in three skills: oil-market-analyst, procurement-advisor, inventory-monitor.
Resilience
Each MCP server is health-checked per request; an unavailable tool is dropped so one down server can't crash a turn.
agent_server/agent.py
Tools
Four sources, one recommendation
1Internal data
get_material_status — parameterized SQL over inventory, quotes and demand; returns stock (with reorder warnings), cheapest current quote, near-term demand.
2Oil market
Current WTI/Brent spot price, history and trend from the U.S. EIA API. Key drives buy timing.
UC MCP Service · EIA API3Deal quality
predict_deal_quality — a GradientBoosting model trained on purchase history, served scale-to-zero.
4Procurement Playbook
Policy & contract rules — approval thresholds, preferred suppliers, MOQ/price-lock — via vector search.
Managed MCP · parsed PDFs → VSGoverned guidance · Beta
Skills — loaded live from Unity Catalog
A skill is a loadable instruction sheet (SKILL.md), not a tool that does work — the model load_skills it, then follows its approach using the four tools above. That load is itself a tool call (you'll see load_skill in the trace) — but what comes back is guidance, not an action.
- Three playbooks as securables —
catalog.schema.skillunder the schema's Skills tab: oil-market-analyst, procurement-advisor, inventory-monitor. - Loaded live over the managed skills MCP (
/ai-gateway/skills/…), filtered to read tools (list_skills,load_skill,get_skill_files) — the agent reads skills but can't create or delete them. - Governed & live — agent SP granted
READ_VOLUME; edit a skill and re-publish and it takes effect with no app redeploy. - Gotcha: skills describe tools by capability — never hardcode a bare tool name (the UC Functions MCP namespaces it to
jywu__jywu_mfg_agent__get_material_status).
Data layer · jywu.jywu_mfg_agent
Small, realistic, labeled
| Table | Rows | Purpose |
|---|---|---|
| supplier_quotes | 36 | vendor pricing, lead times, MOQ, validity |
| inventory_levels | 6 | stock, safety stock, days of supply, reorder point |
| production_demand | 9 | upcoming material requirements by month |
| purchase_history | 24 | past decisions with outcome labels — ML training data |
| procurement_docs | 8 | Procurement Playbook — source for the Vector Search index |
Materials HDPE · LDPE · PP · suppliers ChemCorp · PolySource · AsiaResin · EuroChem · warehouses Houston · Chicago.
Memory & observability
Context that persists, behavior you can inspect
Short-term memory
AsyncDatabricksSession → Lakebase autoscaling Postgres, scoped by session_id, so multi-turn conversations keep context.
Tracing & eval
Every turn is traced to an MLflow experiment. Optional OpenTelemetry dual-export ships traces to an external backend without losing Databricks tracing.
Separate experiments
The agent's tracing experiment is kept distinct from the ML model's training experiment — different concerns.
Governed by Unity Catalog
Tables, the model, and the vector index are all UC securables with grants to the app's service principal.
Authorization architecture
One request, a chain of identities
- LLM · Foundation Model servingCAN QUERY
- UC Functions MCPEXECUTE
- AI Search MCPread
- UC Skills MCPREAD_VOLUME
- Lakebase · session memoryPostgres grants
Deployment
Bundles & a reproducible prep runbook
- Agent app ships as a Databricks Asset Bundle; runtime config (model, catalog, warehouse, MCP URLs, Lakebase) lives in the bundle's
config.env. - MCP servers deploy as separate Databricks Apps (
apps create→sync→apps deploy). - Prep runbook (
setup/README.md): data → pricing model → policy PDFs → AI-functions chunks index → UC governance (connections / services / function) → grants.
Design decisions & lessons
What shaped the build
| Decision | Why |
|---|---|
| Custom tools as MCP servers on Apps | Reusable across agents; lower latency than UC-function tools. |
| Lean model requirements | Inferred deps pulled the whole venv (PySpark, 150+ pkgs) into the serving image — huge, slow build. An explicit 5-package list builds fast anywhere. |
| Direct FM serving, gateway by flag | Works where the FM path is enabled; one env flag adapts to workspaces where it isn't. |
| Managed MCP for retrieval | Endorsed, internal path — no egress concerns for vector search. |
No uv.lock in the deploy | Build's uv version differed from local, tripping --locked; let the build resolve from pyproject. |
End to end · live on the deployed agent
“Buy 200t HDPE at $1,300/ton?”
The recommendation is grounded in specific numbers from each source — inventory, market, model, and policy — not a generic answer.