Skip to content

OpenAI Agents SDK Stateful Agent with db-openai sdk example - #40

Open
jennsun wants to merge 5 commits into
bbqiu/mainfrom
openai-short-term-agent
Open

OpenAI Agents SDK Stateful Agent with db-openai sdk example#40
jennsun wants to merge 5 commits into
bbqiu/mainfrom
openai-short-term-agent

Conversation

@jennsun

@jennsun jennsun commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

Stateful Agent that takes in session id where session id can be any meaningful identifier, like

User-based: "user_12345"
Thread-based: "thread_abc123"
Context-based: "support_ticket_456"

(note: should be uuid for optimal postgres performance as suggested by Jonathan K, lakebase pm)

Tool-calling/MCP calling agent using OpenAI SDK

Based off of https://github.com/databricks/app-templates/tree/main/agent-openai-agents-sdk agent example

Example stateful queries:

curl -X POST http://localhost:8000/invocations \
    -H "Content-Type: application/json" \
    -d '{"input": [{"role": "user", "content": "Hello I live in SF!"}]}'

gives:

{"object":"response","output":[{"type":"message","id":"__fake_id__","content":[{"annotations":[],"text":"Hello! It's great to meet someone from San Francisco. That's a beautiful city with so much to offer - from the iconic Golden Gate Bridge to diverse neighborhoods, amazing food, and a unique culture. \n\nIs there anything specific about San Francisco you'd like to discuss or any questions you have about your city? I'm happy to chat about SF or help with any information you might need.","type":"output_text","logprobs":[]}],"role":"assistant","status":"completed"}],"custom_outputs":{"session_id":"2da30773-637a-4578-bd13-ab7eaeb8253e"}}

follow-up stateful question:

curl -X POST http://localhost:8000/invocations \
    -H "Content-Type: application/json" \
    -d '{
        "input": [{"role": "user", "content": "What city did I say I live in?"}],
        "custom_inputs": {"session_id": "2da30773-637a-4578-bd13-ab7eaeb8253e"}
    }'

gives us:

{"object":"response","output":[{"type":"message","id":"__fake_id__","content":[{"annotations":[],"text":"You said you live in SF, which is commonly understood to be San Francisco, California.","type":"output_text","logprobs":[]}],"role":"assistant","status":"completed"}],"custom_outputs":{"session_id":"2da30773-637a-4578-bd13-ab7eaeb8253e"}}

Tested locally + with app:
image

image

App: https://eng-ml-agent-platform.staging.cloud.databricks.com/apps/j-openai-stateful?o=2850744067564480

image image

with streaming:
image

Ensuring agent messages are logged in lakebase instance:
image

@jennsun jennsun changed the title [draft] OpenAI short term agent [draft] OpenAI Agents SDK short term agent with db-openai sdk Dec 12, 2025
@jennsun jennsun changed the title [draft] OpenAI Agents SDK short term agent with db-openai sdk OpenAI Agents SDK short term agent with db-openai sdk Dec 13, 2025
@jennsun jennsun changed the title OpenAI Agents SDK short term agent with db-openai sdk OpenAI Agents SDK Stateful Agent with db-openai sdk Example Dec 13, 2025
@jennsun jennsun changed the title OpenAI Agents SDK Stateful Agent with db-openai sdk Example OpenAI Agents SDK Stateful Agent with db-openai sdk example Dec 13, 2025
@jennsun
jennsun marked this pull request as ready for review December 18, 2025 21:11
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