Skip to content

Conversation

@sicoyle
Copy link
Contributor

@sicoyle sicoyle commented Jan 6, 2026

Description

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

It introduces response caching support via metadata passed to LLM providers. This serves as a workaround for LangChain’s WithPromptCaching(true) option, which currently sets a boolean value that fails Dapr conformance tests because OpenAI-based providers expect a duration string rather than a boolean.

To properly validate this workaround, usage metrics support was added, which required additional data type translations within LangChain.

The PR also renames CacheTTL to ResponseCacheTTL to more accurately reflect its behavior. Backward compatibility is maintained by continuing to support the original JSON tag.

Finally, the LangChain dependency was updated to support the newly required options that I am using.

Reconfirmed things work as expected:

✗  go test -v -tags=conftests -count=1 --failfast ./tests/conformance -run="TestConversationConformance/openai"
=== RUN   TestConversationConformance
=== RUN   TestConversationConformance/openai.openai
=== RUN   TestConversationConformance/openai.openai/init
=== RUN   TestConversationConformance/openai.openai/converse
=== RUN   TestConversationConformance/openai.openai/converse/get_a_non-empty_response_without_errors
=== RUN   TestConversationConformance/openai.openai/converse/test_user_message_type
=== RUN   TestConversationConformance/openai.openai/converse/test_system_message_type
=== RUN   TestConversationConformance/openai.openai/converse/test_assistant_message_type
=== RUN   TestConversationConformance/openai.openai/converse/test_developer_message_type
=== RUN   TestConversationConformance/openai.openai/converse/test_tool_message_type_-_confirming_active_tool_calling_capability_(empty_tool_choice)
=== RUN   TestConversationConformance/openai.openai/converse/test_conversation_history_with_tool_calls
=== RUN   TestConversationConformance/openai.openai/converse/test_prompt_cache_retention
    conversation.go:577: Request 1 Response Content: "2 + 2 equals 4."
    conversation.go:578: Request 1 Response Length: 15 characters
    conversation.go:583: Request 1 Usage - Total: 1038, Prompt: 1030, Completion: 8
    conversation.go:586: Request 1 Prompt Details - Cached: 1024, Audio: 0
    conversation.go:635: Request 2 Usage - Total: 1038, Prompt: 1030, Completion: 8
    conversation.go:638: Request 2 Prompt Details - Cached: 1024, Audio: 0
    conversation.go:640: Cached tokens on second request: 1024
=== RUN   TestConversationConformance/openai.azure
    conversation_test.go:83: Skipping Azure OpenAI conformance test: AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_TYPE, and AZURE_OPENAI_API_VERSION environment variables must be set
--- PASS: TestConversationConformance (6.41s)
    --- PASS: TestConversationConformance/openai.openai (6.40s)
        --- PASS: TestConversationConformance/openai.openai/init (0.00s)
        --- PASS: TestConversationConformance/openai.openai/converse (6.40s)
            --- PASS: TestConversationConformance/openai.openai/converse/get_a_non-empty_response_without_errors (0.62s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_user_message_type (0.68s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_system_message_type (0.87s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_assistant_message_type (0.56s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_developer_message_type (1.11s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_tool_message_type_-_confirming_active_tool_calling_capability_(empty_tool_choice) (0.98s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_conversation_history_with_tool_calls (0.77s)
            --- PASS: TestConversationConformance/openai.openai/converse/test_prompt_cache_retention (0.82s)
    --- SKIP: TestConversationConformance/openai.azure (0.00s)
PASS
ok      github.com/dapr/components-contrib/tests/conformance    7.439s

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

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:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation
    • Created the dapr/docs PR:

Note: We expect contributors to open a corresponding documentation PR in the dapr/docs repository. As the implementer, you are the best person to document your work! Implementation PRs will not be merged until the documentation PR is opened and ready for review.

@sicoyle sicoyle requested review from a team as code owners January 6, 2026 22:47
Signed-off-by: Samantha Coyle <[email protected]>
Signed-off-by: Samantha Coyle <[email protected]>
// NOTE: These are all translations due to langchaingo data types.

// extractInt64FromGenInfo extracts an int64 value from genInfo map to extract usage data from langchaingo's GenerationInfo map in the choices response.
func extractInt64FromGenInfo(genInfo map[string]any, key string) int64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not return an error here when the value is not a number? Do we not expect other number types (uint)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially defined this as int64 only in my original PR. However, after splitting this effort and what I'm assuming is a subsequent version bump, my conformance tests were no longer returning usage metrics, which required loosening the handling here. This change resolved the issue.

TLDR: Yes, I can add support for uint as a defensive measure and return an error for any other types.

Metadata map[string]string `json:"metadata"`
Model *string `json:"model"`

PromptCacheRetention time.Duration `json:"promptCacheRetention"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be optional?

Suggested change
PromptCacheRetention time.Duration `json:"promptCacheRetention"`
PromptCacheRetention *time.Duration `json:"promptCacheRetention"`

Signed-off-by: Samantha Coyle <[email protected]>
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.

2 participants