|
348 | 348 | end |
349 | 349 | end |
350 | 350 |
|
| 351 | + context "with tool_calls stored using string keys" do |
| 352 | + let(:context_with_string_tool_calls) do |
| 353 | + { |
| 354 | + conversation_history: [ |
| 355 | + { role: :user, content: "What's the weather in SF?" }, |
| 356 | + { |
| 357 | + role: :assistant, |
| 358 | + content: "Let me check that for you", |
| 359 | + tool_calls: [ |
| 360 | + { "id" => "call_123", "name" => "get_weather", "arguments" => { "location" => "SF" } } |
| 361 | + ] |
| 362 | + }, |
| 363 | + { role: :tool, content: "72°F, Sunny", tool_call_id: "call_123" }, |
| 364 | + { role: :assistant, content: "It's 72°F and sunny in SF!" } |
| 365 | + ] |
| 366 | + } |
| 367 | + end |
| 368 | + |
| 369 | + before do |
| 370 | + stub_simple_chat("Clear skies ahead!") |
| 371 | + end |
| 372 | + |
| 373 | + it "restores tool_calls and tool results when tool_call ids are string keyed" do |
| 374 | + result = runner.run(agent, "Anything else?", context: context_with_string_tool_calls) |
| 375 | + |
| 376 | + expect(result.success?).to be true |
| 377 | + |
| 378 | + tool_message = result.messages.find { |msg| msg[:role] == :tool } |
| 379 | + expect(tool_message).not_to be_nil |
| 380 | + expect(tool_message[:tool_call_id]).to eq("call_123") |
| 381 | + |
| 382 | + assistant_with_tools = result.messages.find do |msg| |
| 383 | + msg[:role] == :assistant && msg[:tool_calls]&.any? |
| 384 | + end |
| 385 | + expect(assistant_with_tools).not_to be_nil |
| 386 | + expect(assistant_with_tools[:tool_calls].first[:id]).to eq("call_123") |
| 387 | + end |
| 388 | + end |
| 389 | + |
351 | 390 | context "with empty tool result" do |
352 | 391 | let(:context_with_empty_tool_result) do |
353 | 392 | { |
|
0 commit comments