Skip to content

Add agent-openai-scratch template (raw FastAPI) - #264

Draft
elainemwang wants to merge 13 commits into
databricks:mainfrom
elainemwang:add-agent-openai-scratch
Draft

Add agent-openai-scratch template (raw FastAPI)#264
elainemwang wants to merge 13 commits into
databricks:mainfrom
elainemwang:add-agent-openai-scratch

Conversation

@elainemwang

@elainemwang elainemwang commented Aug 25, 2026

Copy link
Copy Markdown

An OpenAI Agents SDK agent served from a hand-written FastAPI app. mason/wire/serve.py builds the Responses API surface: /invocations + /responses (sync, SSE streaming, in-memory background), GET /responses/{id}, /health, with per-request MLflow spans. Local-first (SQLite sessions), optional managed session store + tracing.

An OpenAI Agents SDK agent served from a hand-written FastAPI app instead of MLflow's
AgentServer. mason/wire/serve.py builds the Responses API surface: /invocations + /responses
(sync, SSE streaming, in-memory background), GET /responses/{id}, /health, with per-request
MLflow spans. Local-first (SQLite sessions), optional managed session store + tracing.

Co-authored-by: Isaac <no-reply@databricks.com>
@elainemwang elainemwang changed the title Add agent-openai-scratch template (raw FastAPI, no serving framework) Add agent-openai-scratch template (raw FastAPI) Aug 25, 2026
elainemwang and others added 8 commits August 25, 2026 23:16
…r types)

Handlers and the wire layer now pass plain Responses-shaped dicts instead of
ResponsesAgentRequest/Response. session_id round-trips as a top-level request/response field
(no custom_inputs/custom_outputs). Removes mlflow.types.responses from the wire layer.

Co-authored-by: Isaac <no-reply@databricks.com>
The FastAPI endpoints (build_app) only depend on the invoke_handler/stream_handler dict
contract, not the agent SDK — so they live in server/app.py, and start_server.py just wires
the agent's handlers in and runs uvicorn. Another SDK's template can reuse server/app.py verbatim.

Co-authored-by: Isaac <no-reply@databricks.com>
Removes the input dedup + MLflow-eval string-content coercion. With a session_id the session
supplies prior history, so clients send only the new turn's message. inbound.py is now just
get_session_id. Tracing is unaffected (lives in server/app.py + mason/tracing.py).

Co-authored-by: Isaac <no-reply@databricks.com>
outbound.py now serializes each StreamEvent under its own type ({type, data} for
raw_response_event; {type, name, item} for run_item_stream_event) instead of reshaping into
Responses events. The client receives the SDK's native event shape as JSON — no imposed
contract — symmetric with how the langgraph template will emit its native events.

Co-authored-by: Isaac <no-reply@databricks.com>
The hand-rolled server's span name wasn't surfacing as the trace name; set the
mlflow.traceName tag explicitly in each handler's span so traces are labeled in the UI.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
deploy.yml ran databricks bundle (needs a databricks.yml this template doesn't ship) and
hardcoded a stale app name; this template deploys via 'databricks apps deploy' (see README).
Also corrects wire/__init__ + README to say outbound serializes SDK events (no Responses reshaping).

Co-authored-by: Isaac <no-reply@databricks.com>
Removes the gallery resource contract so this template isn't offered in the Create-App-from-
Template flow; it's provisioned/configured via the CLI (env + resources) or manual apps deploy.
Follows templates like rag-chat / content-moderator that ship without a manifest.

Co-authored-by: Isaac <no-reply@databricks.com>
Comment thread agent-openai-scratch/server/app.py Outdated
return f"data: {json.dumps(data) if isinstance(data, dict) else data}\n\n"


class _BackgroundRuns:

@elainemwang elainemwang Aug 26, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we go with the durable execution library approach, that would be able to replace this class fully.

elainemwang and others added 4 commits August 26, 2026 01:14
Relocates the background-run store out of server/app.py into its own mason module (public
BackgroundRuns, durability-swap docstring). server/app.py imports it and is now byte-identical
to the agent-langgraph-scratch template's serving layer. Docs point the store at
mason/background.py while server/app.py does the wiring.

Co-authored-by: Isaac <no-reply@databricks.com>
…sts to AGENTS

Neither is imported since dropping AgentServer; verified boot + tracing + tool calls still work
without them. AGENTS.md gains a Sample requests section (sync / streaming / background / multi-turn).

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
README is the canonical request reference (literal http://localhost:8000 URLs, copy-pasteable);
AGENTS drops its duplicate sample-requests block and links to the README Client contract section.

Co-authored-by: Isaac <no-reply@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant