Skip to content

feat(conversation): add prompt cache + usage metrics to test cache#9265

Closed
sicoyle wants to merge 4 commits into
dapr:masterfrom
sicoyle:feat-convo-api-prompt-cache
Closed

feat(conversation): add prompt cache + usage metrics to test cache#9265
sicoyle wants to merge 4 commits into
dapr:masterfrom
sicoyle:feat-convo-api-prompt-cache

Conversation

@sicoyle

@sicoyle sicoyle commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR breaks out work from a larger contrib PR into a smaller, more focused change: #9241

It reviews the Conversation API from a Dapr Agents perspective, evaluates which fields are required, and aligns the API more closely with OpenAI’s where appropriate (including adding fields now and documenting candidates for future support).

Specifically, this PR:

  • Clarifies the semantics of the metadata field to represent request-level metadata passed through to the LLM provider, rather than component metadata as some documentation currently implies.

  • Adds a field to enable prompt caching. Dapr currently supports response caching only; this change mirrors OpenAI’s API, allows per-request configuration, and raises the question of whether prompt caching should also be supported as a global, component-level setting.

  • Adds token usage metrics as a result of testing that prompt caching indeed works.

  • Updates the LangChain dependency.

  • Updates integration tests to reflect the API changes.

Note: This PR depends on the corresponding components-contrib change being merged first for the build to pass: dapr/components-contrib#4154

Issue reference

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

@sicoyle
sicoyle requested review from a team as code owners January 6, 2026 22:55
Comment thread dapr/proto/runtime/v1/ai.proto Outdated
Signed-off-by: Samantha Coyle <[email protected]>
Comment on lines +74 to +78
// Set of 16 key-value pairs that can be attached to the conversation.
// This can be useful for storing additional information about the object in a structured format,
// and querying for objects via API or the dashboard.
// Keys are strings with a maximum length of 64 characters.
// Values are strings with a maximum length of 512 characters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than this being a field on the request message, should the information which will be set here, go into the HTTP or gRPC request header itself? This is with the assumption that users of Dapr aren't expected to add anything here, and the presence of this field is confusing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree headers would be better. However, this field is already implemented in the SDKs, used in docs/quickstarts, and matches OpenAI's ChatCompletion API metadata field (https://github.com/openai/openai-go/blob/main/chatcompletion.go#L3010), which is passed through to LLM providers. To avoid breaking Alpha2 clients, I'd prefer to keep it for now with a comment noting it will move to headers in a future version. This preserves backward compatibility while aligning with OpenAI's API structure.

Comment thread dapr/proto/runtime/v1/ai.proto Outdated
// inspired by openai.ChatCompletion.Usage of type CompletionUsage
message ConversationResultAlpha2CompletionUsage {
// Number of tokens in the generated completion.
int64 completion_tokens = 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should all these count fields be unsigned rather than signed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I matched openai directly here but will update.

if err != nil {
return nil, err
}
request.Metadata = req.GetMetadata()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here, we would take the metadata from the ctx, rather than from the request field.

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.

3 participants