feat(agenticclaude): expose cache_creation_input_tokens + Vertex explicit credentials - #970
Open
sin-bufan wants to merge 4 commits into
Open
Conversation
…icit credentials 1. Expose cache_creation_input_tokens in AgenticMessage.Extra The Anthropic API reports cache_creation_input_tokens separately from input_tokens, but toTokenUsage() sums them into PromptTokens and the breakdown is lost. This makes accurate cost calculation impossible for consumers (e.g. Langfuse). Fix: populate msg.Extra["_eino_claude_cache_creation_input_tokens"] in both non-streaming (toAgenticMessage) and streaming (MessageDeltaEvent) paths. The key matches the legacy claude adapter for downstream compatibility. 2. Add Credentials field to GoogleVertexAIConfig The Vertex path previously only supported ambient ADC via vertex.WithGoogleAuth, forcing callers to use os.Setenv which is process-global and unsafe under concurrency or hot-reload. Fix: add optional *google.Credentials field. When set, use vertex.WithCredentials instead. Falls back to WithGoogleAuth when nil. Co-authored-by: Cursor <cursoragent@cursor.com>
When Gemini returns consecutive chunks each containing a single function_tool_call, they shared the same streaming index because populateStreamingMeta only incremented the index on block type change. ConcatAgenticMessages then tried to merge different tool calls (e.g. 'skill' and 'read_file') and failed with: "expected tool name 'skill' for function tool call, but got 'read_file'" Fix: advance curIndex after the last block if it is a discrete type (function_tool_call, function_tool_result, server_tool_*, mcp_tool_*). These types are self-contained and should never be concatenated across chunks. Co-authored-by: Cursor <cursoragent@cursor.com>
convFunctionToolCall now treats empty string Arguments as an empty object instead of failing with unmarshal error. This prevents NodeRunError when a model returns a tool call with no arguments (e.g. task_complete). Co-authored-by: Cursor <cursoragent@cursor.com>
Fall back to CallID when Name is missing so Gemini API requests with function_response parts remain valid. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cache_creation_input_tokensinAgenticMessage.Extrausing the same key as the legacy claude adapter (_eino_claude_cache_creation_input_tokens). Without this, the value is summed intoPromptTokensand the breakdown is lost, making accurate cost calculation impossible.*google.Credentialsfield toGoogleVertexAIConfig. When set, usesvertex.WithCredentialsinstead of ambient ADC (vertex.WithGoogleAuth), avoiding process-globalos.Setenv("GOOGLE_APPLICATION_CREDENTIALS", ...)which is unsafe under concurrency.Changes
consts.goKeyOfCacheCreationInputTokensconstantconvertor.gomsg.ExtraintoAgenticMessage(non-streaming)event_convertor.gomsg.ExtrainMessageDeltaEventhandler (streaming)model.goCredentials *google.CredentialstoGoogleVertexAIConfig; usevertex.WithCredentialswhen setTest plan
go build ./...passesgo test ./...passes (all existing tests green)Made with Cursor