feat: add OpenAI-compatible Conversations API #351
The item API contract does not match OpenAI. CreateItemRequest requires {"item": {...}}, and the endpoint returns a single ItemResponse. OpenAI accepts {"items": [...]} and returns a list of typed conversation items. Returned items expose their fields directly, without an additional item wrapper. See the OpenAI reference.
A valid OpenAI request therefore fails deserialization here. The new tests assert the same incompatible structure, so passing them does not establish compatibility.
As requested in my review of #166, please record these operations against OpenAI and the gateway, then use those recordings to define the request/response types and compatibility assertions. Preserve a canonical item ID across creation, listing, retrieval, and Responses output.
The new item operations and existing Responses persistence do not agree on tenant ownership. These queries require tenant_id, but ConversationStore::persist_impl() still calls item::create_in_tx(), which inserts items without it.
Consequently, creating a conversation and completing a /v1/responses turn leaves persisted items that the new listing endpoint cannot see. Retrieval and deletion also exclude those rows.
Please extend the existing persistence APIs and update their callers instead of introducing a separate creation path with different tenant semantics. Add an integration test that creates a conversation, executes a response, then lists and retrieves the persisted items through the conversation endpoints.
The hard-coded "default_tenant" must also be resolved consistently across these paths. Storage-level tenant tests alone do not verify tenant isolation at the HTTP boundary.
This repeats the architectural feedback I left on #166. Adding store() here and making ConversationStore::pool() public lets the HTTP handlers reach through ExecutionContext and bypass the application boundary.
Please preserve this layering:
HTTP handler
→ typed operations on exec_ctx.conv_handler
ConversationHandler
→ ConversationStore
Storage
→ database models and queries
The new entrypoints need corresponding typed operations on ConversationHandler, following the existing Responses and conversation pattern. Request validation, item identity, storage conversion, and StorageError → ExecutorError translation should happen behind that boundary. Axum should extract the request, call the operation, and serialize its typed result.
Currently, conversation_items.rs imports database models, accesses the raw pool, generates item IDs, serializes storage payloads, and handles database failures directly. conversations.rs also deserializes stored metadata.
Please move these responsibilities behind ConversationHandler and remove the new public store/pool accessors. Referencing exec_ctx in the call chain does not preserve the boundary when the handler immediately reaches through it to storage.
This PR adds local CRUD tests, but no OpenAI reference recordings, matching gateway recordings, or replay assertions for the new routes.
Please extend the recorder with scenarios covering conversation create/retrieve/update/delete and item create/list/retrieve/delete. Record each scenario against OpenAI and against the gateway with its database and vLLM running. Cover supported item formats, generated-ID reuse, pagination, include, invalid requests, and error responses.
The recordings also need to cover the stateful behavior described in my earlier comment:
previous_response_id.Use equivalent requests and prompts, normalize dynamic IDs and timestamps, and compare status codes, response shapes, ordering, pagination, ID relationships, and history visibility. For streaming Responses calls, also compare the SSE lifecycle.
The existing conv recorder mode does not exercise these management routes. Please add repeatable recording scripts and Rust integration assertions using the recorded OpenAI behavior as the reference. Captured cassette YAML must be generated by the recorder, not hand-authored.
Moving the limit into SQL addresses part of my earlier feedback, but the cursor predicate does not match the ordering: after filters by id > cursor, while results are ordered by seq, id. IDs are generated before insertion, so their order can differ from insertion order and cause pagination to skip or repeat items.
Please resolve the cursor within the same conversation and tenant, then paginate using the actual ordering keys.
ListItemsQuery also omits order and include. The query always returns ascending order, whereas OpenAI defaults to descending order. Please implement the recorded behavior and explicitly reject unsupported include values instead of silently ignoring them. See the OpenAI list reference.
Finally, the HTTP handler uses filter_map with db_item.as_inout(), silently dropping malformed stored items after calculating has_more. This can return an incomplete or empty page with misleading pagination metadata. Please perform a fallible typed conversion behind the application boundary and propagate conversion errors.
Thanks for working on the Conversations API support! I’ve left inline comments covering the application/storage boundary, OpenAI compatibility, and cassette coverage. Please take a look and address those before we move forward. Some revisit feedback from #166, which I’ve linked for context. Happy to clarify anything that’s unclear.
The item endpoints duplicate the same hard-coded default_tenant mapping, so their tenant filters do not isolate authenticated callers. A caller from any tenant can operate on resources in this shared namespace if it knows the IDs. Use the authenticated principal's tenant identity consistently for item operations.
This helper ignores the authenticated request and assigns every caller to default_tenant. When OIDC is enabled, authenticated tenants therefore share the same namespace and can access or mutate one another's conversations by ID; the tenant predicates below do not provide isolation if the tenant is never extracted. Read the principal's tenant here (and return an authentication error when it is absent) before exposing these operations.
The conversation row is inserted before initial items are serialized and inserted through a separate transaction. If serialization or item insertion fails, this endpoint returns an error but leaves an empty or partial conversation behind. Create the conversation and its initial items in one transaction so the request is atomic.
Adding tenant_id to Item is not propagated through the existing response persistence path: ConversationStore::persist still calls create_in_tx, whose INSERT omits this column. Consequently, input/output items appended by Responses have NULL tenant IDs and disappear from these tenant-scoped list/retrieve/delete endpoints even for conversations created by this API. Pass the authorized tenant through response persistence or migrate/handle those rows explicitly.
This issue also appears in the following locations of the same file:
Because InputItem's custom deserializer returns InputItem::Unknown for unrecognized type values instead of failing, this untagged enum accepts output-only items such as web_search_call or mcp_call as Input(Unknown); the Output branch is never reached for them. Those items are therefore persisted and returned with the wrong type. Dispatch by the discriminator or make unknown input variants fail so supported output variants can be selected.
This route addition does not include the Responses integration described for this PR. RequestPayload still exposes only conversation_id, rehydration still calls get_or_create, and response delivery still emits conversation_id, so standard conversation requests/response objects and unknown-ID 404 behavior remain unimplemented. Please add that integration or narrow the PR scope.
<!-- ccr-overview-v2 -->
Copilot review overview
🟡 Changes recommended
Tenant isolation remains hard-coded to default_tenant, and Responses integration is incomplete.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> · 4 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>
<details open>
<summary><strong>Open (6)</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
Adds OpenAI-compatible conversation and item CRUD APIs with tenant-scoped storage, pagination, schemas, and integration tests. Approval is blocked by unresolved tenant isolation and incomplete Responses integration.
Changes:
| File | Summary |
|---|---|
| scripts/setup-postgres-test.sh | PostgreSQL test setup |
| crates/agentic-server/tests/conversations_test.rs | Conversation API integration tests |
| crates/agentic-server/tests/common/mod.rs | Test helper annotations |
| crates/agentic-server/src/openapi.rs | OpenAPI registrations |
| crates/agentic-server/src/handler/mod.rs | Handler exports |
| crates/agentic-server/src/handler/http/mod.rs | HTTP module exports |
| crates/agentic-server/src/handler/http/conversations.rs | Conversation CRUD handlers |
| crates/agentic-server/src/handler/http/conversation_items.rs | Item handlers and pagination |
| crates/agentic-server/src/handler/common.rs | JSON and error helpers |
| crates/agentic-server/src/app.rs | Conversation route registration |
| crates/agentic-server-core/tests/tenant_isolation_test.rs | SQLite tenant-isolation tests |
| crates/agentic-server-core/tests/postgres_tenant_isolation_test.rs | PostgreSQL tenant-isolation tests |
| crates/agentic-server-core/src/types/mod.rs | Type exports |
| crates/agentic-server-core/src/types/conversations.rs | Conversation API schemas |
| crates/agentic-server-core/src/storage/types/conversation.rs | Tenant conversation data |
| crates/agentic-server-core/src/storage/models/item.rs | Tenant item persistence and queries |
| crates/agentic-server-core/src/storage/models/conversation.rs | Tenant conversation queries |
| crates/agentic-server-core/src/storage/conversation.rs | Conversation store operations |
| crates/agentic-server-core/src/executor/modes/conversation.rs | Store access for handlers |
</details>
---
💡 <a href="/vllm-project/agentic-api/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
The tenant_id now flows consistently from HTTP extraction → ExecuteRequest → rehydrate → RequestContext → execute_turn → persist → storage, ensuring items created via /v1/responses will be visible to the onversations items API endpoints.
Updated as per OpenAI API contract.
Approved these changes.
All the layering violations have been fixed.
@avinashsingh77 unfortunately I still see the ConversationStore being exposed and dont see the preserved layers either and PR has been merged. Perhaps could help to address this in another PR along with the cassettes recording in https://github.com/vllm-project/agentic-api/pull/351#discussion_r4060744768 to ensure correct compatibility with OpenAI conversation items contract?
I believe you are are talking about building a comprehensive testing infrastructure addition that goes significantly beyond the current PR scope. Here's what would need to be built:
Required Work as per my understanding:
1. New Specialized Recorder:
The existing record_cassette.py only handles /v1/responses and /v1/messages. The Conversations API requires a new recorder that:
- Makes HTTP calls to multiple endpoints (conversations, items)
- Chains responses correctly (conversation IDs, item IDs)
- Interleaves CRUD operations with inference calls
- Normalizes dynamic IDs/timestamps for comparison
2. Recording Scenarios (~10-15 cassettes)
Basic CRUD (8 cassettes):
- Conversation create/retrieve/update/delete × streaming/non-streaming
- Items create/list/retrieve/delete × streaming/non-streaming
Stateful Behavior (6+ cassettes):
- Manual items → model context (the critical test)
- Item deletion → continuation divergence
- Branching before/after manual item addition
3. Replay Tests
Integration tests that:
- Load OpenAI reference cassettes
- Load gateway cassettes
- Compare status codes, shapes, ordering, pagination, ID relationships
- Assert history visibility matches
4. Recording Scripts
Similar to record_web_search_cassettes.sh, record_custom_tool_cassettes.sh, etc
@maralbahari Should I add basic integration tests now (using real DB but no cassettes), defer cassette infrastructure to a follow-up PR.
Sorry @maralbahari I am yet to push latest changes.
I am not sure how this PR was merged.
I will file a follow up PR to address all 4 review comments and cassettes recording .
@avinashsingh77 no worries. Thanks for the help. once open the PR let me know
franciscojavierarceo
avinashsingh77
Summary
Add conversation and item CRUD endpoints, including metadata updates, batch item creation, retrieval, deletion, and cursor pagination. Requests use an
itemsarray; returned items expose their typed fields directly; listing supports ascending and descending order; deleting an item returns its conversation.Conversation ownership governs item access, including items written by Responses persistence. Item creation shares the existing conversation lock and sequence allocator. Deletion detaches items so stored response history survives, and a persisted conversation revision rejects turns prepared before an item mutation. Conversation creation and its initial items commit atomically.
Add migration
0005_conversation_revision.sql, update supervisor-managed PostgreSQL upgrade instructions, and run PostgreSQL conversation CRUD and tenant-isolation tests in CI.Authentication integration remains a follow-up: HTTP handlers currently use
default_tenant. Storage operations enforce the supplied tenant; these endpoints do not yet derive it from the authenticated principal.Fixes: #155
Test Plan
agentic-server/vendored-opensslfeature because this host lacks system OpenSSL headers.