Bug Description
When using Claude model with tool calling (via GenerateWithTools), a panic occurs after tool execution completes: index out of range [-1] at claude.go:598.
Environment
- eino-ext/components/model/claude: v0.1.16
- Go: 1.25+
- Backend: TaskManager with Agent tool calling
Steps to Reproduce
- Configure Claude provider with tool calling enabled
- Send a message that triggers tool calling
- After tool execution returns (with JSON output), the LLM call crashes
Root Cause Analysis
In claude.go:598, the code accesses msgParam.Content[len(msgParam.Content)-1] without checking if Content is empty:
if ctrl := msgParam.Content[len(msgParam.Content)-1].GetCacheControl(); ctrl != nil && ctrl.Type != "" {
hasSetMsgBreakPoint = true
}
When convSchemaMessage processes a message that only contains tool calls (no text content), the returned msgParam.Content can be empty. This causes an index out of range panic when the code tries to access the last element.
Suggested Fix
Add a length check before accessing Content:
if len(msgParam.Content) > 0 {
if ctrl := msgParam.Content[len(msgParam.Content)-1].GetCacheControl(); ctrl != nil && ctrl.Type != "" {
hasSetMsgBreakPoint = true
}
}
Additional Context
This affects tool calling scenarios where the Assistant message has ToolCalls but empty Content, and the subsequent Tool message returns a result.
Bug Description
When using Claude model with tool calling (via GenerateWithTools), a panic occurs after tool execution completes: index out of range [-1] at claude.go:598.
Environment
Steps to Reproduce
Root Cause Analysis
In claude.go:598, the code accesses msgParam.Content[len(msgParam.Content)-1] without checking if Content is empty:
When convSchemaMessage processes a message that only contains tool calls (no text content), the returned msgParam.Content can be empty. This causes an index out of range panic when the code tries to access the last element.
Suggested Fix
Add a length check before accessing Content:
Additional Context
This affects tool calling scenarios where the Assistant message has ToolCalls but empty Content, and the subsequent Tool message returns a result.