diff --git a/.changeset/nine-eggs-retire.md b/.changeset/nine-eggs-retire.md new file mode 100644 index 000000000000..7777feedaf19 --- /dev/null +++ b/.changeset/nine-eggs-retire.md @@ -0,0 +1,5 @@ +--- +'@ai-sdk/anthropic': patch +--- + +Add support for 2025-08-25 code execution tool diff --git a/content/providers/01-ai-sdk-providers/05-anthropic.mdx b/content/providers/01-ai-sdk-providers/05-anthropic.mdx index 6343a12cac55..c7ada79b52e2 100644 --- a/content/providers/01-ai-sdk-providers/05-anthropic.mdx +++ b/content/providers/01-ai-sdk-providers/05-anthropic.mdx @@ -547,7 +547,9 @@ You can enable code execution using the provider-defined code execution tool: ```ts import { anthropic } from '@ai-sdk/anthropic'; import { generateText } from 'ai'; -const codeExecutionTool = anthropic.tools.codeExecution_20250522(); + +const codeExecutionTool = anthropic.tools.codeExecution_20250825(); + const result = await generateText({ model: anthropic('claude-opus-4-20250514'), prompt: diff --git a/examples/ai-core/src/generate-text/anthropic-code-execution-20250825.ts b/examples/ai-core/src/generate-text/anthropic-code-execution-20250825.ts new file mode 100644 index 000000000000..44059a531a61 --- /dev/null +++ b/examples/ai-core/src/generate-text/anthropic-code-execution-20250825.ts @@ -0,0 +1,17 @@ +import { anthropic } from '@ai-sdk/anthropic'; +import { generateText } from 'ai'; +import { run } from '../lib/run'; + +run(async () => { + const result = await generateText({ + model: anthropic('claude-sonnet-4-5'), + prompt: + 'Write a Python script to calculate fibonacci number' + + ' and then execute it to find the 10th fibonacci number', + tools: { + code_execution: anthropic.tools.codeExecution_20250825(), + }, + }); + + console.dir(result.content, { depth: Infinity }); +}); diff --git a/examples/ai-core/src/stream-text/anthropic-code-execution-20250825.ts b/examples/ai-core/src/stream-text/anthropic-code-execution-20250825.ts new file mode 100644 index 000000000000..78fec4faca40 --- /dev/null +++ b/examples/ai-core/src/stream-text/anthropic-code-execution-20250825.ts @@ -0,0 +1,46 @@ +import { anthropic } from '@ai-sdk/anthropic'; +import { streamText } from 'ai'; +import { run } from '../lib/run'; + +run(async () => { + const result = streamText({ + model: anthropic('claude-sonnet-4-5'), + prompt: + 'Write a Python script to calculate fibonacci number' + + ' and then execute it to find the 10th fibonacci number', + tools: { + code_execution: anthropic.tools.codeExecution_20250825(), + }, + includeRawChunks: true, + }); + + for await (const part of result.fullStream) { + switch (part.type) { + case 'text-delta': { + process.stdout.write(part.text); + break; + } + + case 'tool-call': { + process.stdout.write( + `\n\nTool call: '${part.toolName}'\nInput: ${JSON.stringify(part.input, null, 2)}\n`, + ); + break; + } + + case 'tool-result': { + process.stdout.write( + `\nTool result: '${part.toolName}'\nOutput: ${JSON.stringify(part.output, null, 2)}\n`, + ); + break; + } + + case 'error': { + console.error('\n\nCode execution error:', part.error); + break; + } + } + } + + process.stdout.write('\n\n'); +}); diff --git a/examples/next-openai/agent/anthropic-code-execution.ts b/examples/next-openai/agent/anthropic-code-execution.ts new file mode 100644 index 000000000000..454b231e59ad --- /dev/null +++ b/examples/next-openai/agent/anthropic-code-execution.ts @@ -0,0 +1,13 @@ +import { anthropic } from '@ai-sdk/anthropic'; +import { BasicAgent, InferAgentUIMessage } from 'ai'; + +export const anthropicCodeExecutionAgent = new BasicAgent({ + model: anthropic('claude-sonnet-4-5'), + tools: { + code_execution: anthropic.tools.codeExecution_20250825(), + }, +}); + +export type AnthropicCodeExecutionMessage = InferAgentUIMessage< + typeof anthropicCodeExecutionAgent +>; diff --git a/examples/next-openai/app/api/chat-anthropic-code-execution/route.ts b/examples/next-openai/app/api/chat-anthropic-code-execution/route.ts new file mode 100644 index 000000000000..f561f1f8337b --- /dev/null +++ b/examples/next-openai/app/api/chat-anthropic-code-execution/route.ts @@ -0,0 +1,12 @@ +import { anthropicCodeExecutionAgent } from '@/agent/anthropic-code-execution'; +import { validateUIMessages } from 'ai'; + +export async function POST(request: Request) { + const body = await request.json(); + + console.dir(body.messages, { depth: Infinity }); + + return anthropicCodeExecutionAgent.respond({ + messages: await validateUIMessages({ messages: body.messages }), + }); +} diff --git a/examples/next-openai/app/chat-anthropic-code-execution/page.tsx b/examples/next-openai/app/chat-anthropic-code-execution/page.tsx new file mode 100644 index 000000000000..02aff58ecab9 --- /dev/null +++ b/examples/next-openai/app/chat-anthropic-code-execution/page.tsx @@ -0,0 +1,56 @@ +'use client'; + +import { AnthropicCodeExecutionMessage } from '@/agent/anthropic-code-execution'; +import { Response } from '@/components/ai-elements/response'; +import ChatInput from '@/components/chat-input'; +import AnthropicCodeExecutionView from '@/components/tool/anthropic-code-execution-view'; +import { useChat } from '@ai-sdk/react'; +import { DefaultChatTransport } from 'ai'; + +export default function TestAnthropicCodeExecution() { + const { error, status, sendMessage, messages, regenerate } = + useChat({ + transport: new DefaultChatTransport({ + api: '/api/chat-anthropic-code-execution', + }), + }); + + return ( +
+

Anthropic Code Execution Test

+ + {messages.map(message => ( +
+ {message.role === 'user' ? 'User: ' : 'AI: '} + {message.parts.map((part, index) => { + switch (part.type) { + case 'text': { + return {part.text}; + } + case 'tool-code_execution': { + return ( + + ); + } + } + })} +
+ ))} + + {error && ( +
+
An error occurred.
+ +
+ )} + + sendMessage({ text })} /> +
+ ); +} diff --git a/examples/next-openai/components/tool/anthropic-code-execution-view.tsx b/examples/next-openai/components/tool/anthropic-code-execution-view.tsx new file mode 100644 index 000000000000..dc53d23361b5 --- /dev/null +++ b/examples/next-openai/components/tool/anthropic-code-execution-view.tsx @@ -0,0 +1,229 @@ +import { anthropic } from '@ai-sdk/anthropic'; +import { UIToolInvocation } from 'ai'; + +export default function AnthropicCodeExecutionView({ + invocation, +}: { + invocation: UIToolInvocation< + ReturnType + >; +}) { + switch (invocation.state) { + case 'input-streaming': + case 'input-available': { + return ; + } + case 'output-available': + return ( + <> + + +
+
+              {invocation.output.type === 'bash_code_execution_result' && (
+                <>
+                  Stdout:
+                  
+ {invocation.output.stdout} +
+ {invocation.output.stderr && ( + <> + Stderr: +
+ {invocation.output.stderr} +
+ + )} + {invocation.output.return_code != null && ( + <> + Return Code: +
+ {invocation.output.return_code} +
+ + )} + + )} + {invocation.output.type === + 'bash_code_execution_tool_result_error' && ( + <> + Bash Tool Result Error +
+ Error Code:{' '} + {invocation.output.error_code} +
+ + )} + {invocation.output.type === + 'text_editor_code_execution_create_result' && ( + <> + File Create Result +
+ Is File Update:{' '} + {invocation.output.is_file_update ? 'Yes' : 'No'} +
+ + )} + {invocation.output.type === + 'text_editor_code_execution_view_result' && ( + <> + File View Result +
+ File Type:{' '} + {invocation.output.file_type} +
+ Content: +
+ {invocation.output.content} +
+ + )} + {invocation.output.type === + 'text_editor_code_execution_str_replace_result' && ( + <> + File Str Replace Result +
+ New Start:{' '} + {invocation.output.new_start} +
+ New Lines:{' '} + {invocation.output.new_lines} +
+ Old Start:{' '} + {invocation.output.old_start} +
+ Old Lines:{' '} + {invocation.output.old_lines} +
+ Lines: +
+ {invocation.output.lines?.join('\n')} +
+ + )} + {invocation.output.type === + 'text_editor_code_execution_tool_result_error' && ( + <> + + Text Editor Tool Result Error + +
+ Error Code:{' '} + {invocation.output.error_code} +
+ + )} +
+
+ + ); + } +} + +function InputView({ + input, +}: { + input: UIToolInvocation< + ReturnType + >['input']; +}) { + switch (input?.type) { + case 'text_editor_code_execution': { + switch (input.command) { + case 'view': { + return ( +
+
+                Text Editor (View)
+                
+ {input.path && ( + <> + File Path:{' '} + {input.path} +
+ + )} +
+
+ ); + } + case 'create': { + return ( +
+
+                Text Editor (Create)
+                
+ {input.path && ( + <> + File Path:{' '} + {input.path} +
+ + )} + {input.file_text && ( + <> + File Text:{' '} + {input.file_text} +
+ + )} +
+
+ ); + } + case 'str_replace': { + return ( +
+
+                Text Editor (Replace)
+                
+ {input.path && ( + <> + File Path:{' '} + {input.path} +
+ + )} + {input.old_str && ( + <> + Old String: +
+ {input.old_str} +
+ + )} + {input.new_str && ( + <> + New String: +
+ {input.new_str} +
+ + )} +
+
+ ); + } + } + } + + case 'bash_code_execution': { + const command = input.command; + + return ( +
+
+            Bash
+            
+ {command && ( + <> + Command: {command} +
+ + )} +
+
+ ); + } + } +} diff --git a/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt b/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt new file mode 100644 index 000000000000..c7173b597278 --- /dev/null +++ b/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.chunks.txt @@ -0,0 +1,248 @@ +{"type":"message_start","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_01LEsrXVCLpf7xHaFdFTZNEJ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":2263,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":8,"service_tier":"standard"}}} +{"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} +{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"I'll create a Python script to calculate"}} +{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" Fibonacci numbers and then execute it to fin"}} +{"type":"ping"} +{"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"d the 10th Fibonacci number."}} +{"type":"content_block_stop","index":0} +{"type":"content_block_start","index":1,"content_block":{"type":"server_tool_use","id":"srvtoolu_0112cP8RpnKv67t2cscmN4ia","name":"text_editor_code_execution","input":{}}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":""}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"{\""}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"comma"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"nd\": \"c"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"reate\""}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":", \""}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"path\": "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"/"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"tmp/fi"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"bonacci."}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"py\""}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":", \"file_"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"text\":"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \"def fib"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"onacci(n):"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\n \\\"\\\"\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"\\n Calc"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ulate th"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"e nth Fibo"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"nacc"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"i "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"numb"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"er.\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n Ar"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"gs:"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" n: T"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"he "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"positio"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n i"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n the Fibon"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"acci s"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"eq"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"uence (1-"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"indexe"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"d)\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Returns:\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" The n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"th "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"Fibonac"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ci num"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"be"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"r\\n \\\"\\\"\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" if"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" n <= 0"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":":\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" return \\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"Pleas"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"e enter a "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"positive int"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"eg"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"er"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\\"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" elif n =="}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" 1:\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" retu"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"rn "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"0\\n el"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"if n == 2:\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" return "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"1\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" else:\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" # Usi"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ng"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" itera"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"tive ap"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"proa"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ch "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"for effi"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ciency\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" a,"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" b"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" = 0"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":", 1"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"for _ in ra"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"nge(2, n):\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" a"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":", b = b, "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"a + b\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" ret"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"urn "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"b\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\ndef fi"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"bonacci_rec"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ursive(n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"):\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\\"\\\"\\\"\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Ca"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"lcula"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"te the nth"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Fibonacci"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" numb"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"er using r"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ecursion.\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Arg"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"s:\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" n:"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" The po"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"si"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"tion in "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"the Fibona"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"cci sequen"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ce (1-index"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ed)\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Returns:\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" The nth F"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ibonacci n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"umber\\n \\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"\\\"\\\"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"if n <"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"= 0:\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" retu"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"rn \\\"Plea"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"se enter a"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" positive in"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"teger\\\"\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" elif n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"== 1"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":":\\n r"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"et"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ur"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n 0\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" elif n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" == 2:\\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" return"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" 1\\n els"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"e:\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"return fib"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"onacci_recur"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"sive(n-1) +"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" fib"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"onacci_re"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"cursive(n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"-2)\\n\\nif "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"__name__ =="}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" \\\"_"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"_main_"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"_\\\":\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" # "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"Calcula"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"te "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"the 1"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"0th Fibonacc"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"i numb"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"er\\n n = "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"10\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"result = fi"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"bonacc"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"i(n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":")\\n \\n"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" print("}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"f\\\"The"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" {n}t"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"h Fibonac"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ci numb"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"er"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" is: {resul"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"t}"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\\")\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"n \\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" # Sho"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"w the "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"first 10 "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"Fibona"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"cci numb"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ers\\n p"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"ri"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"nt(f\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"\\\\nFirst "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"{n}"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" Fibon"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"acci numbe"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"rs:\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\")"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\n fo"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"r i in range"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"(1, n + "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"1):\\n "}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":" pr"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"int(f\\"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\"F({i"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"}) = {"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"fibonacci"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"(i)}\\\")"}} +{"type":"content_block_delta","index":1,"delta":{"type":"input_json_delta","partial_json":"\\n\"}"}} +{"type":"content_block_stop","index":1} +{"type":"content_block_start","index":2,"content_block":{"type":"text_editor_code_execution_tool_result","tool_use_id":"srvtoolu_0112cP8RpnKv67t2cscmN4ia","content":{"type":"text_editor_code_execution_create_result","is_file_update":false}}} +{"type":"content_block_stop","index":2} +{"type":"content_block_start","index":3,"content_block":{"type":"text","text":""}} +{"type":"content_block_delta","index":3,"delta":{"type":"text_delta","text":"Now let's"}} +{"type":"content_block_delta","index":3,"delta":{"type":"text_delta","text":" execute the script to find the 10th Fibonacci"}} +{"type":"content_block_delta","index":3,"delta":{"type":"text_delta","text":" number:"}} +{"type":"content_block_stop","index":3} +{"type":"content_block_start","index":4,"content_block":{"type":"server_tool_use","id":"srvtoolu_01K2E2j5mkxbtLqNBc6RJHds","name":"bash_code_execution","input":{}}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":""}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":"{\"command"}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":"\": \"python"}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":" /tmp/fibon"}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":"ac"}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":"ci.py"}} +{"type":"content_block_delta","index":4,"delta":{"type":"input_json_delta","partial_json":"\"}"}} +{"type":"content_block_stop","index":4} +{"type":"content_block_start","index":5,"content_block":{"type":"bash_code_execution_tool_result","tool_use_id":"srvtoolu_01K2E2j5mkxbtLqNBc6RJHds","content":{"type":"bash_code_execution_result","stdout":"The 10th Fibonacci number is: 34\n\nFirst 10 Fibonacci numbers:\nF(1) = 0\nF(2) = 1\nF(3) = 1\nF(4) = 2\nF(5) = 3\nF(6) = 5\nF(7) = 8\nF(8) = 13\nF(9) = 21\nF(10) = 34\n","stderr":"","return_code":0,"content":[]}}} +{"type":"content_block_stop","index":5} +{"type":"content_block_start","index":6,"content_block":{"type":"text","text":""}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"Perfect"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"! The script has been created an"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"d executed successfully. \n\n**Result"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":": The 10th Fibonacci number is"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":" 34**\n\nThe script includes:\n1"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":". An **iterative function** (`"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"fibonacci`) - efficient and fast, suitable for larger numbers"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"\n2. A **recursive function** (`fibonacci_recursive`) - sim"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"pler but less efficient for large values\n3. The main execution"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":" block that calculates and displays the 10th Fibonacci number"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"\n4. A bonus display showing all"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":" Fibonacci numbers from F(1) to F(10)"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"\n\nThe Fibonacci sequence starts with 0, "}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"1, and each subsequent number is the sum of the"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":" previous two numbers: "}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"0, 1, 1,"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":" 2, 3, 5"}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":", 8, 13, "}} +{"type":"content_block_delta","index":6,"delta":{"type":"text_delta","text":"21, 34, ..."}} +{"type":"content_block_stop","index":6} +{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"container":{"id":"container_011CU6pTr2hLT47seQ5Xs4yj","expires_at":"2025-10-14T10:02:00.044495Z"}},"usage":{"input_tokens":8050,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":771,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0}}} +{"type":"message_stop"} \ No newline at end of file diff --git a/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.json b/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.json new file mode 100644 index 000000000000..d8fb0cf3f8a0 --- /dev/null +++ b/packages/anthropic/src/__fixtures__/anthropic-code-execution-20250825.1.json @@ -0,0 +1,70 @@ +{ + "model": "claude-sonnet-4-5-20250929", + "id": "msg_01Wx5dv3Qisv7pjTdanFgc9Q", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "I'll create a Python script to calculate Fibonacci numbers and then execute it to find the 10th Fibonacci number." + }, + { + "type": "server_tool_use", + "id": "srvtoolu_012LCpyzxGBy44bCW4zCxmH2", + "name": "text_editor_code_execution", + "input": { + "command": "create", + "path": "/tmp/fibonacci.py", + "file_text": "def fibonacci(n):\n \"\"\"\n Calculate the nth Fibonacci number.\n \n Args:\n n: The position in the Fibonacci sequence (1-indexed)\n \n Returns:\n The nth Fibonacci number\n \"\"\"\n if n <= 0:\n raise ValueError(\"n must be a positive integer\")\n elif n == 1 or n == 2:\n return 1\n \n # Using iterative approach for efficiency\n fib_prev = 1 # F(1)\n fib_curr = 1 # F(2)\n \n for i in range(3, n + 1):\n fib_next = fib_prev + fib_curr\n fib_prev = fib_curr\n fib_curr = fib_next\n \n return fib_curr\n\n\nif __name__ == \"__main__\":\n # Calculate the 10th Fibonacci number\n n = 10\n result = fibonacci(n)\n print(f\"The {n}th Fibonacci number is: {result}\")\n \n # Display the first 10 Fibonacci numbers for reference\n print(f\"\\nFirst {n} Fibonacci numbers:\")\n for i in range(1, n + 1):\n print(f\"F({i}) = {fibonacci(i)}\")\n" + } + }, + { + "type": "text_editor_code_execution_tool_result", + "tool_use_id": "srvtoolu_012LCpyzxGBy44bCW4zCxmH2", + "content": { + "type": "text_editor_code_execution_create_result", + "is_file_update": false + } + }, + { "type": "text", "text": "Now let me execute the script:" }, + { + "type": "server_tool_use", + "id": "srvtoolu_01KqzcSjepCqNjqeUVqnmEjj", + "name": "bash_code_execution", + "input": { "command": "python /tmp/fibonacci.py" } + }, + { + "type": "bash_code_execution_tool_result", + "tool_use_id": "srvtoolu_01KqzcSjepCqNjqeUVqnmEjj", + "content": { + "type": "bash_code_execution_result", + "stdout": "The 10th Fibonacci number is: 55\n\nFirst 10 Fibonacci numbers:\nF(1) = 1\nF(2) = 1\nF(3) = 2\nF(4) = 3\nF(5) = 5\nF(6) = 8\nF(7) = 13\nF(8) = 21\nF(9) = 34\nF(10) = 55\n", + "stderr": "", + "return_code": 0, + "content": [] + } + }, + { + "type": "text", + "text": "Perfect! The script has been created and executed successfully. \n\n**Result: The 10th Fibonacci number is 55**\n\nThe script uses an iterative approach to calculate Fibonacci numbers efficiently, which is better than a recursive approach for larger values of n (avoiding exponential time complexity). The Fibonacci sequence shown is: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55..." + } + ], + "container": { + "id": "container_011CU6rVteVhydYXRyNs6G1M", + "expires_at": "2025-10-14T10:28:40.590791Z" + }, + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 7881, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 608, + "service_tier": "standard", + "server_tool_use": { "web_search_requests": 0, "web_fetch_requests": 0 } + } +} diff --git a/packages/anthropic/src/__snapshots__/anthropic-messages-language-model.test.ts.snap b/packages/anthropic/src/__snapshots__/anthropic-messages-language-model.test.ts.snap index c31b70728f83..0f73790eb110 100644 --- a/packages/anthropic/src/__snapshots__/anthropic-messages-language-model.test.ts.snap +++ b/packages/anthropic/src/__snapshots__/anthropic-messages-language-model.test.ts.snap @@ -1,5 +1,76 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`AnthropicMessagesLanguageModel > doGenerate > code execution 20250825 > should include code execution tool call and result in content 1`] = ` +[ + { + "text": "I'll create a Python script to calculate Fibonacci numbers and then execute it to find the 10th Fibonacci number.", + "type": "text", + }, + { + "input": "{"type":"text_editor_code_execution","command":"create","path":"/tmp/fibonacci.py","file_text":"def fibonacci(n):\\n \\"\\"\\"\\n Calculate the nth Fibonacci number.\\n \\n Args:\\n n: The position in the Fibonacci sequence (1-indexed)\\n \\n Returns:\\n The nth Fibonacci number\\n \\"\\"\\"\\n if n <= 0:\\n raise ValueError(\\"n must be a positive integer\\")\\n elif n == 1 or n == 2:\\n return 1\\n \\n # Using iterative approach for efficiency\\n fib_prev = 1 # F(1)\\n fib_curr = 1 # F(2)\\n \\n for i in range(3, n + 1):\\n fib_next = fib_prev + fib_curr\\n fib_prev = fib_curr\\n fib_curr = fib_next\\n \\n return fib_curr\\n\\n\\nif __name__ == \\"__main__\\":\\n # Calculate the 10th Fibonacci number\\n n = 10\\n result = fibonacci(n)\\n print(f\\"The {n}th Fibonacci number is: {result}\\")\\n \\n # Display the first 10 Fibonacci numbers for reference\\n print(f\\"\\\\nFirst {n} Fibonacci numbers:\\")\\n for i in range(1, n + 1):\\n print(f\\"F({i}) = {fibonacci(i)}\\")\\n"}", + "providerExecuted": true, + "toolCallId": "srvtoolu_012LCpyzxGBy44bCW4zCxmH2", + "toolName": "code_execution", + "type": "tool-call", + }, + { + "providerExecuted": true, + "result": { + "is_file_update": false, + "type": "text_editor_code_execution_create_result", + }, + "toolCallId": "srvtoolu_012LCpyzxGBy44bCW4zCxmH2", + "toolName": "code_execution", + "type": "tool-result", + }, + { + "text": "Now let me execute the script:", + "type": "text", + }, + { + "input": "{"type":"bash_code_execution","command":"python /tmp/fibonacci.py"}", + "providerExecuted": true, + "toolCallId": "srvtoolu_01KqzcSjepCqNjqeUVqnmEjj", + "toolName": "code_execution", + "type": "tool-call", + }, + { + "providerExecuted": true, + "result": { + "content": [], + "return_code": 0, + "stderr": "", + "stdout": "The 10th Fibonacci number is: 55 + +First 10 Fibonacci numbers: +F(1) = 1 +F(2) = 1 +F(3) = 2 +F(4) = 3 +F(5) = 5 +F(6) = 8 +F(7) = 13 +F(8) = 21 +F(9) = 34 +F(10) = 55 +", + "type": "bash_code_execution_result", + }, + "toolCallId": "srvtoolu_01KqzcSjepCqNjqeUVqnmEjj", + "toolName": "code_execution", + "type": "tool-result", + }, + { + "text": "Perfect! The script has been created and executed successfully. + +**Result: The 10th Fibonacci number is 55** + +The script uses an iterative approach to calculate Fibonacci numbers efficiently, which is better than a recursive approach for larger values of n (avoiding exponential time complexity). The Fibonacci sequence shown is: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...", + "type": "text", + }, +] +`; + exports[`AnthropicMessagesLanguageModel > doGenerate > web fetch tool > text response > should include web fetch tool call and result in content 1`] = ` [ { @@ -462,15 +533,15 @@ For the most current breaking tech news today, I'd recommend checking major tech ] `; -exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > web fetch tool > txt response > should stream web search tool results 1`] = ` +exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > code execution 20250825 tool > should stream code execution tool results 1`] = ` [ { "type": "stream-start", "warnings": [], }, { - "id": "msg_01GpfwV1W5Ase72fzb8F45bX", - "modelId": "claude-sonnet-4-20250514", + "id": "msg_01LEsrXVCLpf7xHaFdFTZNEJ", + "modelId": "claude-sonnet-4-5-20250929", "type": "response-metadata", }, { @@ -478,12 +549,17 @@ exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > web fetch tool "type": "text-start", }, { - "delta": "I'll fetch the content", + "delta": "I'll create a Python script to calculate", "id": "0", "type": "text-delta", }, { - "delta": " from that Wikipedia page to tell you what it's about.", + "delta": " Fibonacci numbers and then execute it to fin", + "id": "0", + "type": "text-delta", + }, + { + "delta": "d the 10th Fibonacci number.", "id": "0", "type": "text-delta", }, @@ -492,282 +568,1561 @@ exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > web fetch tool "type": "text-end", }, { - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "providerExecuted": true, - "toolName": "web_fetch", + "toolName": "code_execution", "type": "tool-input-start", }, { - "delta": "", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "{"type": "text_editor_code_execution","", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "{"url": ", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "comma", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": ""https:/", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "nd": "c", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "/en.wi", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "reate"", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "kip", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": ", "", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "ed", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "path": ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "ia.org/", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": ""/", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "wiki/", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "tmp/fi", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "Maglemosian", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "bonacci.", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "delta": "_culture"}", - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "delta": "py"", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", "type": "tool-input-delta", }, { - "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", - "type": "tool-input-end", + "delta": ", "file_", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "input": "{"url": "https://en.wikipedia.org/wiki/Maglemosian_culture"}", - "providerExecuted": true, - "toolCallId": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", - "toolName": "web_fetch", - "type": "tool-call", + "delta": "text":", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "result": { - "content": { - "citations": undefined, - "source": { - "data": "This article needs additional citations for -| -![]() | -The -| ----| -Maglemosian (c. 9000 – c. 6000 BC) is the name given to a [culture](https://en.wikipedia.org/wiki/Archaeological_culture) of the early [Mesolithic](https://en.wikipedia.org/wiki/Mesolithic) period in [Northern Europe](https://en.wikipedia.org/wiki/Northern_Europe). In [Scandinavia](https://en.wikipedia.org/wiki/Scandinavia), the culture was succeeded by the [Kongemose](https://en.wikipedia.org/wiki/Kongemose_culture) culture. -The name originates from the [Danish](https://en.wikipedia.org/wiki/Denmark) archeological site Maglemose, situated near [Gørlev](https://en.wikipedia.org/wiki/Gørlev) and [Høng](https://en.wikipedia.org/wiki/Høng) on western [Zealand](https://en.wikipedia.org/wiki/Zealand_(Denmark)), southwest of lake [Tissø](https://en.wikipedia.org/wiki/Tissø). Here the first settlement of the culture was excavated in 1900, by George Sarauw.[[1]](./Maglemosian_culture#cite_note-1) During the following century a long series of similar settlements were excavated from [England](https://en.wikipedia.org/wiki/England) to [Poland](https://en.wikipedia.org/wiki/Poland) and from [Skåne](https://en.wikipedia.org/wiki/Skåne) in [Sweden](https://en.wikipedia.org/wiki/Sweden) to northern [France](https://en.wikipedia.org/wiki/France). -When the Maglemosian culture flourished, sea levels were much lower than now and what is now mainland Europe and Scandinavia were linked with Britain. The cultural period overlaps the end of the [last ice age](https://en.wikipedia.org/wiki/Weichselian_glaciation),[[2]](./Maglemosian_culture#cite_note-2) when the ice retreated and the glaciers melted. It was a long process and sea levels in [Northern Europe](https://en.wikipedia.org/wiki/Northern_Europe) did not reach current levels until almost 6000 BC, by which time they had inundated large territories previously inhabited by Maglemosian people. Therefore, there is hope that the emerging discipline of [underwater archaeology](https://en.wikipedia.org/wiki/Underwater_archaeology) may reveal interesting findings related to the Maglemosian culture in the future. -The Maglemosian people lived in forest and wetland environments, using fishing and hunting tools made from wood, bone, and flint [microliths](https://en.wikipedia.org/wiki/Microlith). It appears that they had domesticated the [dog](https://en.wikipedia.org/wiki/Dog).[[3]](./Maglemosian_culture#cite_note-3) Some may have lived settled lives, but most were nomadic.[[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)] -Huts made of bark have been preserved, in addition to tools made of [flint](https://en.wikipedia.org/wiki/Flint), [bone](https://en.wikipedia.org/wiki/Bone), and [horn](https://en.wikipedia.org/wiki/Horn_(anatomy)). A characteristic feature of the culture is the sharply edged [microliths](https://en.wikipedia.org/wiki/Microlith) of flintstone, used for spear and arrow heads.[[4]](./Maglemosian_culture#cite_note-4) Another notable feature is the [leister](https://en.wikipedia.org/wiki/Leister), a characteristic type of fishing spear, used for [gigging](https://en.wikipedia.org/wiki/Gigging). -Era | Timespan | -| ----| -![]() | -This section needs expansion. You can help by [adding to it](//en.wikipedia.org/w/index.php?title=Maglemosian_culture&action=edit§ion=). (January 2020) -[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-1)[Sarauw, G. F. L.](https://en.wikipedia.org/wiki/Georg_F.L._Sarauw)(1903).["En Stenaldersboplads i Maglemose ved Mullerup – sammenholdt med beslægtede fund"](https://books.google.com/books?id=n5VePAAACAAJ)[A Stone Age settlement in Maglemose near Mullerup – compared with related finds. Resumé: Études sur le premier âge de la pierre du Nord de l'Europe]. Aarbøger for Nordisk Oldkyndighed og Historie (in Danish). 1903. A[German](https://en.wikipedia.org/wiki/German_language)translation appeared in Prähistorische Zeitschrift in 1911[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-2)Jessen, Catherine A.; Pedersen, Kristoffer Buck; Christensen, Charlie; Olsen, Jesper; Mortensen, Morten Fischer; Hansen, Keld Møller (2015).["Early Maglemosian culture in the Preboreal landscape: Archaeology and vegetation from the earliest Mesolithic site in Denmark at Lundby Mose, Sjælland"](https://doi.org/10.1016%2Fj.quaint.2014.03.056). Quaternary International. 378: 73–87.[Bibcode](https://en.wikipedia.org/wiki/Bibcode_(identifier)):[2015QuInt.378...73J](https://ui.adsabs.harvard.edu/abs/2015QuInt.378...73J).[doi](https://en.wikipedia.org/wiki/Doi_(identifier)):[10.1016/j.quaint.2014.03.056](https://doi.org/10.1016%2Fj.quaint.2014.03.056).[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-3)["Stone Age remains are Britain's earliest house"](http://www.manchester.ac.uk/discover/news/stone-age-remains-are-britains-earliest-house/). Retrieved 28 January 2018.[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-4)[Med bue, pil og fiskespyd](http://www.denstoredanske.dk/Danmarks_Oldtid/Stenalder/De_vejl%C3%B8se_skove_9.500-6.400_f.Kr/Med_bue,_pil_og_fiskespyd)Gyldendals Open Encyclopedia (in Danish). Pictures of some Maglemosian tools. -- Anders Fischer: "Submerged Stone Age – Danish Examples and North sea potential"; i: N.C.Flemming: Submarine Prehistory and Archaeology of the North Sea: research priorities and collaboration with industry. CBA Research Report 141, 2004, s. 23ff -Danish-language texts -- Geoffrey Bibby: Spadens vidnedsbyrd; Wormanium 1980, -[ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier))[87-8516-071-7](https://en.wikipedia.org/wiki/Special:BookSources/87-8516-071-7)s. 109f - Gyldendal og Politikens Danmarkshistorie (red. af Olaf Olsen); Bind 1: I begyndelsen. Fra de ældste tider til ca. år 200 f.Kr. (ved Jørgen Jensen); 1988, s. 47ff -- Jørgen Jensen: Danmarks Oldtid. Stenalder, 13.000–2.000 f.Kr.; Gyldendal 2001, -[ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier))[87-00-49038-5](https://en.wikipedia.org/wiki/Special:BookSources/87-00-49038-5)s. 86ff - Anders Fischer: "En håndfuld flint", Skalk nr. 5, 1973, s. 8ff -- Anders Fischer: "Mennesket og havet i ældre stenalder"; i: Carin Bunte (red): Arkeologi och Naturvetenskab, Lund 2005, s. 276ff -- Kim Aaris-Sørensen: "Uroksejagt", Skalk nr. 6, 1984, s. 10ff -- Ole Grøn: "Teltning", Skalk nr. 1, 1988, s. 13f -- Søren A. Sørensen: "Hytte ved sø", Skalk nr. 3, 1988, s. 25ff -- Peter Vang Petersen: "Bjørnejagt", Skalk nr. 5, 1991, s. 3ff -- Poul og Kristian Krabbe: "Vest for Valhal", Skalk nr. 6, 1995, s. 11ff -- Axel Degn Johansen: "Ikke en sky og ikke en vind!", Skalk nr 2, 2008, s. 8ff", - "mediaType": "text/plain", - "type": "text", - }, - "title": "Maglemosian culture", - "type": "document", - }, - "retrievedAt": "2025-07-17T21:38:38.606000+00:00", - "type": "web_fetch_result", - "url": "https://en.wikipedia.org/wiki/Maglemosian_culture", - }, - "toolCallId": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", - "toolName": "web_fetch", - "type": "tool-result", + "delta": " "def fib", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "id": "3", - "type": "text-start", + "delta": "onacci(n):", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "This", - "id": "3", - "type": "text-delta", + "delta": "\\n \\"\\"\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " Wikipedia page is about the **Maglemosian culture**, which", - "id": "3", - "type": "text-delta", + "delta": ""\\n Calc", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " was an early Mesolithic (Middle", - "id": "3", - "type": "text-delta", + "delta": "ulate th", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " Stone Age) archaeological culture that existe", - "id": "3", - "type": "text-delta", + "delta": "e nth Fibo", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "d in Northern Europe from approximately 9,000 to ", - "id": "3", - "type": "text-delta", + "delta": "nacc", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "6,000 BC. - -Here are", - "id": "3", - "type": "text-delta", + "delta": "i ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " the key points about what this page covers", - "id": "3", - "type": "text-delta", + "delta": "numb", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": ": - -**Geographic and Temporal Context:** -- The culture", - "id": "3", - "type": "text-delta", + "delta": "er.\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " spanned across Northern Europe, from England to Poland and from southern", - "id": "3", - "type": "text-delta", + "delta": " \\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " Sweden to northern France -- It existe", - "id": "3", - "type": "text-delta", + "delta": "n Ar", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "d during a period when sea levels were much lower an", - "id": "3", - "type": "text-delta", + "delta": "gs:", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "d Britain was connected to mainland Europe", - "id": "3", - "type": "text-delta", + "delta": "\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " -- The culture overlapped with the en", - "id": "3", - "type": "text-delta", + "delta": " n: T", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "d of the last ice age - -**Origins an", - "id": "3", - "type": "text-delta", + "delta": "he ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "d Discovery:** -- Named after the Danish archaeological site Maglem", - "id": "3", - "type": "text-delta", + "delta": "positio", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "ose, located near Gørlev and Høng in", - "id": "3", - "type": "text-delta", + "delta": "n i", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " western Zealand, Denmark -- First", - "id": "3", - "type": "text-delta", + "delta": "n the Fibon", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " excavated in 1900 by", - "id": "3", - "type": "text-delta", + "delta": "acci s", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " George Sarauw -- Similar", - "id": "3", - "type": "text-delta", + "delta": "eq", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " settlements were subsequently discovered across a", - "id": "3", - "type": "text-delta", + "delta": "uence (1-", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " wide area of Northern Europe - -**", - "id": "3", - "type": "text-delta", + "delta": "indexe", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": "Lifestyle and Technology:** -- The Maglemosian people lived in", - "id": "3", - "type": "text-delta", + "delta": "d)\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " forest and wetland environments -- They were", - "id": "3", - "type": "text-delta", + "delta": " \\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " primarily hunter-gatherers who used fishing and hunting tools", - "id": "3", - "type": "text-delta", + "delta": "n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " -- They had domesticated dogs -- Most", - "id": "3", - "type": "text-delta", + "delta": " Returns:\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " were nomadic, though some may have lived more", - "id": "3", - "type": "text-delta", + "delta": "n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " settled lives -- They built huts made", - "id": "3", - "type": "text-delta", + "delta": " The n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", }, { - "delta": " of bark - + "delta": "th ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "Fibonac", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ci num", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "be", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "r\\n \\"\\"\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ""\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " if", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " n <= 0", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ":\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " return \\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ""Pleas", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "e enter a ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "positive int", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "eg", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "er", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\"\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " elif n ==", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " 1:\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " retu", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "rn ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "0\\n el", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "if n == 2:\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " return ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "1\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " else:\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " # Usi", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ng", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " itera", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "tive ap", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "proa", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ch ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "for effi", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ciency\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " a,", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " b", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " = 0", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ", 1", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "for _ in ra", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "nge(2, n):\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " a", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ", b = b, ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "a + b\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " ret", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "urn ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "b\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\ndef fi", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "bonacci_rec", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ursive(n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "):\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " \\"\\"\\"\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " Ca", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "lcula", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "te the nth", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " Fibonacci", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " numb", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "er using r", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ecursion.\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " \\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " Arg", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "s:\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " n:", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " The po", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "si", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "tion in ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "the Fibona", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "cci sequen", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ce (1-index", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ed)\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " \\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " Returns:\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " The nth F", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ibonacci n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "umber\\n \\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ""\\"\\"\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "if n <", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "= 0:\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " retu", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "rn \\"Plea", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "se enter a", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " positive in", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "teger\\"\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " elif n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "== 1", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ":\\n r", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "et", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ur", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "n 0\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " elif n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " == 2:\\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " return", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " 1\\n els", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "e:\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "return fib", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "onacci_recur", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "sive(n-1) +", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " fib", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "onacci_re", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "cursive(n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "-2)\\n\\nif ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "__name__ ==", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " \\"_", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "_main_", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "_\\":\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " # ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "Calcula", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "te ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "the 1", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "0th Fibonacc", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "i numb", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "er\\n n = ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "10\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "result = fi", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "bonacc", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "i(n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ")\\n \\n", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " print(", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "f\\"The", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " {n}t", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "h Fibonac", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ci numb", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "er", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " is: {resul", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "t}", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\")\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "n \\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " # Sho", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "w the ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "first 10 ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "Fibona", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "cci numb", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ers\\n p", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "ri", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "nt(f\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ""\\\\nFirst ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "{n}", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " Fibon", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "acci numbe", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "rs:\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "")", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\n fo", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "r i in range", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "(1, n + ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "1):\\n ", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": " pr", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "int(f\\", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": ""F({i", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "}) = {", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "fibonacci", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "(i)}\\")", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "delta": "\\n"}", + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-delta", + }, + { + "id": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "type": "tool-input-end", + }, + { + "input": "{"type": "text_editor_code_execution","command": "create", "path": "/tmp/fibonacci.py", "file_text": "def fibonacci(n):\\n \\"\\"\\"\\n Calculate the nth Fibonacci number.\\n \\n Args:\\n n: The position in the Fibonacci sequence (1-indexed)\\n \\n Returns:\\n The nth Fibonacci number\\n \\"\\"\\"\\n if n <= 0:\\n return \\"Please enter a positive integer\\"\\n elif n == 1:\\n return 0\\n elif n == 2:\\n return 1\\n else:\\n # Using iterative approach for efficiency\\n a, b = 0, 1\\n for _ in range(2, n):\\n a, b = b, a + b\\n return b\\n\\ndef fibonacci_recursive(n):\\n \\"\\"\\"\\n Calculate the nth Fibonacci number using recursion.\\n \\n Args:\\n n: The position in the Fibonacci sequence (1-indexed)\\n \\n Returns:\\n The nth Fibonacci number\\n \\"\\"\\"\\n if n <= 0:\\n return \\"Please enter a positive integer\\"\\n elif n == 1:\\n return 0\\n elif n == 2:\\n return 1\\n else:\\n return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)\\n\\nif __name__ == \\"__main__\\":\\n # Calculate the 10th Fibonacci number\\n n = 10\\n result = fibonacci(n)\\n \\n print(f\\"The {n}th Fibonacci number is: {result}\\")\\n \\n # Show the first 10 Fibonacci numbers\\n print(f\\"\\\\nFirst {n} Fibonacci numbers:\\")\\n for i in range(1, n + 1):\\n print(f\\"F({i}) = {fibonacci(i)}\\")\\n"}", + "providerExecuted": true, + "toolCallId": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "toolName": "code_execution", + "type": "tool-call", + }, + { + "providerExecuted": true, + "result": { + "is_file_update": false, + "type": "text_editor_code_execution_create_result", + }, + "toolCallId": "srvtoolu_0112cP8RpnKv67t2cscmN4ia", + "toolName": "code_execution", + "type": "tool-result", + }, + { + "id": "3", + "type": "text-start", + }, + { + "delta": "Now let's", + "id": "3", + "type": "text-delta", + }, + { + "delta": " execute the script to find the 10th Fibonacci", + "id": "3", + "type": "text-delta", + }, + { + "delta": " number:", + "id": "3", + "type": "text-delta", + }, + { + "id": "3", + "type": "text-end", + }, + { + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "providerExecuted": true, + "toolName": "code_execution", + "type": "tool-input-start", + }, + { + "delta": "{"type": "bash_code_execution","command", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "delta": "": "python", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "delta": " /tmp/fibon", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "delta": "ac", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "delta": "ci.py", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "delta": ""}", + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-delta", + }, + { + "id": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "type": "tool-input-end", + }, + { + "input": "{"type": "bash_code_execution","command": "python /tmp/fibonacci.py"}", + "providerExecuted": true, + "toolCallId": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "toolName": "code_execution", + "type": "tool-call", + }, + { + "providerExecuted": true, + "result": { + "content": [], + "return_code": 0, + "stderr": "", + "stdout": "The 10th Fibonacci number is: 34 + +First 10 Fibonacci numbers: +F(1) = 0 +F(2) = 1 +F(3) = 1 +F(4) = 2 +F(5) = 3 +F(6) = 5 +F(7) = 8 +F(8) = 13 +F(9) = 21 +F(10) = 34 +", + "type": "bash_code_execution_result", + }, + "toolCallId": "srvtoolu_01K2E2j5mkxbtLqNBc6RJHds", + "toolName": "code_execution", + "type": "tool-result", + }, + { + "id": "6", + "type": "text-start", + }, + { + "delta": "Perfect", + "id": "6", + "type": "text-delta", + }, + { + "delta": "! The script has been created an", + "id": "6", + "type": "text-delta", + }, + { + "delta": "d executed successfully. + +**Result", + "id": "6", + "type": "text-delta", + }, + { + "delta": ": The 10th Fibonacci number is", + "id": "6", + "type": "text-delta", + }, + { + "delta": " 34** + +The script includes: +1", + "id": "6", + "type": "text-delta", + }, + { + "delta": ". An **iterative function** (\`", + "id": "6", + "type": "text-delta", + }, + { + "delta": "fibonacci\`) - efficient and fast, suitable for larger numbers", + "id": "6", + "type": "text-delta", + }, + { + "delta": " +2. A **recursive function** (\`fibonacci_recursive\`) - sim", + "id": "6", + "type": "text-delta", + }, + { + "delta": "pler but less efficient for large values +3. The main execution", + "id": "6", + "type": "text-delta", + }, + { + "delta": " block that calculates and displays the 10th Fibonacci number", + "id": "6", + "type": "text-delta", + }, + { + "delta": " +4. A bonus display showing all", + "id": "6", + "type": "text-delta", + }, + { + "delta": " Fibonacci numbers from F(1) to F(10)", + "id": "6", + "type": "text-delta", + }, + { + "delta": " + +The Fibonacci sequence starts with 0, ", + "id": "6", + "type": "text-delta", + }, + { + "delta": "1, and each subsequent number is the sum of the", + "id": "6", + "type": "text-delta", + }, + { + "delta": " previous two numbers: ", + "id": "6", + "type": "text-delta", + }, + { + "delta": "0, 1, 1,", + "id": "6", + "type": "text-delta", + }, + { + "delta": " 2, 3, 5", + "id": "6", + "type": "text-delta", + }, + { + "delta": ", 8, 13, ", + "id": "6", + "type": "text-delta", + }, + { + "delta": "21, 34, ...", + "id": "6", + "type": "text-delta", + }, + { + "id": "6", + "type": "text-end", + }, + { + "finishReason": "stop", + "providerMetadata": { + "anthropic": { + "cacheCreationInputTokens": 0, + "stopSequence": null, + "usage": { + "cache_creation": { + "ephemeral_1h_input_tokens": 0, + "ephemeral_5m_input_tokens": 0, + }, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "input_tokens": 8050, + "output_tokens": 771, + "server_tool_use": { + "web_fetch_requests": 0, + "web_search_requests": 0, + }, + "service_tier": "standard", + }, + }, + }, + "type": "finish", + "usage": { + "cachedInputTokens": 0, + "inputTokens": 2263, + "outputTokens": 771, + "totalTokens": 3034, + }, + }, +] +`; + +exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > web fetch tool > txt response > should stream web search tool results 1`] = ` +[ + { + "type": "stream-start", + "warnings": [], + }, + { + "id": "msg_01GpfwV1W5Ase72fzb8F45bX", + "modelId": "claude-sonnet-4-20250514", + "type": "response-metadata", + }, + { + "id": "0", + "type": "text-start", + }, + { + "delta": "I'll fetch the content", + "id": "0", + "type": "text-delta", + }, + { + "delta": " from that Wikipedia page to tell you what it's about.", + "id": "0", + "type": "text-delta", + }, + { + "id": "0", + "type": "text-end", + }, + { + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "providerExecuted": true, + "toolName": "web_fetch", + "type": "tool-input-start", + }, + { + "delta": "{"url": ", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": ""https:/", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "/en.wi", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "kip", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "ed", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "ia.org/", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "wiki/", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "Maglemosian", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "delta": "_culture"}", + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-delta", + }, + { + "id": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "type": "tool-input-end", + }, + { + "input": "{"url": "https://en.wikipedia.org/wiki/Maglemosian_culture"}", + "providerExecuted": true, + "toolCallId": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "toolName": "web_fetch", + "type": "tool-call", + }, + { + "result": { + "content": { + "citations": undefined, + "source": { + "data": "This article needs additional citations for +| +![]() | +The +| +---| +Maglemosian (c. 9000 – c. 6000 BC) is the name given to a [culture](https://en.wikipedia.org/wiki/Archaeological_culture) of the early [Mesolithic](https://en.wikipedia.org/wiki/Mesolithic) period in [Northern Europe](https://en.wikipedia.org/wiki/Northern_Europe). In [Scandinavia](https://en.wikipedia.org/wiki/Scandinavia), the culture was succeeded by the [Kongemose](https://en.wikipedia.org/wiki/Kongemose_culture) culture. +The name originates from the [Danish](https://en.wikipedia.org/wiki/Denmark) archeological site Maglemose, situated near [Gørlev](https://en.wikipedia.org/wiki/Gørlev) and [Høng](https://en.wikipedia.org/wiki/Høng) on western [Zealand](https://en.wikipedia.org/wiki/Zealand_(Denmark)), southwest of lake [Tissø](https://en.wikipedia.org/wiki/Tissø). Here the first settlement of the culture was excavated in 1900, by George Sarauw.[[1]](./Maglemosian_culture#cite_note-1) During the following century a long series of similar settlements were excavated from [England](https://en.wikipedia.org/wiki/England) to [Poland](https://en.wikipedia.org/wiki/Poland) and from [Skåne](https://en.wikipedia.org/wiki/Skåne) in [Sweden](https://en.wikipedia.org/wiki/Sweden) to northern [France](https://en.wikipedia.org/wiki/France). +When the Maglemosian culture flourished, sea levels were much lower than now and what is now mainland Europe and Scandinavia were linked with Britain. The cultural period overlaps the end of the [last ice age](https://en.wikipedia.org/wiki/Weichselian_glaciation),[[2]](./Maglemosian_culture#cite_note-2) when the ice retreated and the glaciers melted. It was a long process and sea levels in [Northern Europe](https://en.wikipedia.org/wiki/Northern_Europe) did not reach current levels until almost 6000 BC, by which time they had inundated large territories previously inhabited by Maglemosian people. Therefore, there is hope that the emerging discipline of [underwater archaeology](https://en.wikipedia.org/wiki/Underwater_archaeology) may reveal interesting findings related to the Maglemosian culture in the future. +The Maglemosian people lived in forest and wetland environments, using fishing and hunting tools made from wood, bone, and flint [microliths](https://en.wikipedia.org/wiki/Microlith). It appears that they had domesticated the [dog](https://en.wikipedia.org/wiki/Dog).[[3]](./Maglemosian_culture#cite_note-3) Some may have lived settled lives, but most were nomadic.[[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)] +Huts made of bark have been preserved, in addition to tools made of [flint](https://en.wikipedia.org/wiki/Flint), [bone](https://en.wikipedia.org/wiki/Bone), and [horn](https://en.wikipedia.org/wiki/Horn_(anatomy)). A characteristic feature of the culture is the sharply edged [microliths](https://en.wikipedia.org/wiki/Microlith) of flintstone, used for spear and arrow heads.[[4]](./Maglemosian_culture#cite_note-4) Another notable feature is the [leister](https://en.wikipedia.org/wiki/Leister), a characteristic type of fishing spear, used for [gigging](https://en.wikipedia.org/wiki/Gigging). +Era | Timespan | +| +---| +![]() | +This section needs expansion. You can help by [adding to it](//en.wikipedia.org/w/index.php?title=Maglemosian_culture&action=edit§ion=). (January 2020) +[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-1)[Sarauw, G. F. L.](https://en.wikipedia.org/wiki/Georg_F.L._Sarauw)(1903).["En Stenaldersboplads i Maglemose ved Mullerup – sammenholdt med beslægtede fund"](https://books.google.com/books?id=n5VePAAACAAJ)[A Stone Age settlement in Maglemose near Mullerup – compared with related finds. Resumé: Études sur le premier âge de la pierre du Nord de l'Europe]. Aarbøger for Nordisk Oldkyndighed og Historie (in Danish). 1903. A[German](https://en.wikipedia.org/wiki/German_language)translation appeared in Prähistorische Zeitschrift in 1911[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-2)Jessen, Catherine A.; Pedersen, Kristoffer Buck; Christensen, Charlie; Olsen, Jesper; Mortensen, Morten Fischer; Hansen, Keld Møller (2015).["Early Maglemosian culture in the Preboreal landscape: Archaeology and vegetation from the earliest Mesolithic site in Denmark at Lundby Mose, Sjælland"](https://doi.org/10.1016%2Fj.quaint.2014.03.056). Quaternary International. 378: 73–87.[Bibcode](https://en.wikipedia.org/wiki/Bibcode_(identifier)):[2015QuInt.378...73J](https://ui.adsabs.harvard.edu/abs/2015QuInt.378...73J).[doi](https://en.wikipedia.org/wiki/Doi_(identifier)):[10.1016/j.quaint.2014.03.056](https://doi.org/10.1016%2Fj.quaint.2014.03.056).[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-3)["Stone Age remains are Britain's earliest house"](http://www.manchester.ac.uk/discover/news/stone-age-remains-are-britains-earliest-house/). Retrieved 28 January 2018.[↑](https://en.wikipedia.org/wiki/Maglemosian_culture#cite_ref-4)[Med bue, pil og fiskespyd](http://www.denstoredanske.dk/Danmarks_Oldtid/Stenalder/De_vejl%C3%B8se_skove_9.500-6.400_f.Kr/Med_bue,_pil_og_fiskespyd)Gyldendals Open Encyclopedia (in Danish). Pictures of some Maglemosian tools. +- Anders Fischer: "Submerged Stone Age – Danish Examples and North sea potential"; i: N.C.Flemming: Submarine Prehistory and Archaeology of the North Sea: research priorities and collaboration with industry. CBA Research Report 141, 2004, s. 23ff +Danish-language texts +- Geoffrey Bibby: Spadens vidnedsbyrd; Wormanium 1980, +[ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier))[87-8516-071-7](https://en.wikipedia.org/wiki/Special:BookSources/87-8516-071-7)s. 109f - Gyldendal og Politikens Danmarkshistorie (red. af Olaf Olsen); Bind 1: I begyndelsen. Fra de ældste tider til ca. år 200 f.Kr. (ved Jørgen Jensen); 1988, s. 47ff +- Jørgen Jensen: Danmarks Oldtid. Stenalder, 13.000–2.000 f.Kr.; Gyldendal 2001, +[ISBN](https://en.wikipedia.org/wiki/ISBN_(identifier))[87-00-49038-5](https://en.wikipedia.org/wiki/Special:BookSources/87-00-49038-5)s. 86ff - Anders Fischer: "En håndfuld flint", Skalk nr. 5, 1973, s. 8ff +- Anders Fischer: "Mennesket og havet i ældre stenalder"; i: Carin Bunte (red): Arkeologi och Naturvetenskab, Lund 2005, s. 276ff +- Kim Aaris-Sørensen: "Uroksejagt", Skalk nr. 6, 1984, s. 10ff +- Ole Grøn: "Teltning", Skalk nr. 1, 1988, s. 13f +- Søren A. Sørensen: "Hytte ved sø", Skalk nr. 3, 1988, s. 25ff +- Peter Vang Petersen: "Bjørnejagt", Skalk nr. 5, 1991, s. 3ff +- Poul og Kristian Krabbe: "Vest for Valhal", Skalk nr. 6, 1995, s. 11ff +- Axel Degn Johansen: "Ikke en sky og ikke en vind!", Skalk nr 2, 2008, s. 8ff", + "mediaType": "text/plain", + "type": "text", + }, + "title": "Maglemosian culture", + "type": "document", + }, + "retrievedAt": "2025-07-17T21:38:38.606000+00:00", + "type": "web_fetch_result", + "url": "https://en.wikipedia.org/wiki/Maglemosian_culture", + }, + "toolCallId": "srvtoolu_01VNMRfQny2LCrLKEdYaVcCe", + "toolName": "web_fetch", + "type": "tool-result", + }, + { + "id": "3", + "type": "text-start", + }, + { + "delta": "This", + "id": "3", + "type": "text-delta", + }, + { + "delta": " Wikipedia page is about the **Maglemosian culture**, which", + "id": "3", + "type": "text-delta", + }, + { + "delta": " was an early Mesolithic (Middle", + "id": "3", + "type": "text-delta", + }, + { + "delta": " Stone Age) archaeological culture that existe", + "id": "3", + "type": "text-delta", + }, + { + "delta": "d in Northern Europe from approximately 9,000 to ", + "id": "3", + "type": "text-delta", + }, + { + "delta": "6,000 BC. + +Here are", + "id": "3", + "type": "text-delta", + }, + { + "delta": " the key points about what this page covers", + "id": "3", + "type": "text-delta", + }, + { + "delta": ": + +**Geographic and Temporal Context:** +- The culture", + "id": "3", + "type": "text-delta", + }, + { + "delta": " spanned across Northern Europe, from England to Poland and from southern", + "id": "3", + "type": "text-delta", + }, + { + "delta": " Sweden to northern France +- It existe", + "id": "3", + "type": "text-delta", + }, + { + "delta": "d during a period when sea levels were much lower an", + "id": "3", + "type": "text-delta", + }, + { + "delta": "d Britain was connected to mainland Europe", + "id": "3", + "type": "text-delta", + }, + { + "delta": " +- The culture overlapped with the en", + "id": "3", + "type": "text-delta", + }, + { + "delta": "d of the last ice age + +**Origins an", + "id": "3", + "type": "text-delta", + }, + { + "delta": "d Discovery:** +- Named after the Danish archaeological site Maglem", + "id": "3", + "type": "text-delta", + }, + { + "delta": "ose, located near Gørlev and Høng in", + "id": "3", + "type": "text-delta", + }, + { + "delta": " western Zealand, Denmark +- First", + "id": "3", + "type": "text-delta", + }, + { + "delta": " excavated in 1900 by", + "id": "3", + "type": "text-delta", + }, + { + "delta": " George Sarauw +- Similar", + "id": "3", + "type": "text-delta", + }, + { + "delta": " settlements were subsequently discovered across a", + "id": "3", + "type": "text-delta", + }, + { + "delta": " wide area of Northern Europe + +**", + "id": "3", + "type": "text-delta", + }, + { + "delta": "Lifestyle and Technology:** +- The Maglemosian people lived in", + "id": "3", + "type": "text-delta", + }, + { + "delta": " forest and wetland environments +- They were", + "id": "3", + "type": "text-delta", + }, + { + "delta": " primarily hunter-gatherers who used fishing and hunting tools", + "id": "3", + "type": "text-delta", + }, + { + "delta": " +- They had domesticated dogs +- Most", + "id": "3", + "type": "text-delta", + }, + { + "delta": " were nomadic, though some may have lived more", + "id": "3", + "type": "text-delta", + }, + { + "delta": " settled lives +- They built huts made", + "id": "3", + "type": "text-delta", + }, + { + "delta": " of bark + **Distinctive Tools", "id": "3", "type": "text-delta", @@ -882,11 +2237,6 @@ exports[`AnthropicMessagesLanguageModel > doStream > raw chunks > web search too "toolName": "web_search", "type": "tool-input-start", }, - { - "delta": "", - "id": "srvtoolu_01Bj5uzzLcYG5hfueSLcDH8k", - "type": "tool-input-delta", - }, { "delta": "{"query": "t", "id": "srvtoolu_01Bj5uzzLcYG5hfueSLcDH8k", diff --git a/packages/anthropic/src/anthropic-messages-api.ts b/packages/anthropic/src/anthropic-messages-api.ts index bad29cec3b62..d2b13798eb34 100644 --- a/packages/anthropic/src/anthropic-messages-api.ts +++ b/packages/anthropic/src/anthropic-messages-api.ts @@ -34,6 +34,8 @@ export interface AnthropicAssistantMessage { | AnthropicCodeExecutionToolResultContent | AnthropicWebFetchToolResultContent | AnthropicWebSearchToolResultContent + | AnthropicBashCodeExecutionToolResultContent + | AnthropicTextEditorCodeExecutionToolResultContent >; } @@ -98,7 +100,14 @@ export interface AnthropicToolCallContent { export interface AnthropicServerToolUseContent { type: 'server_tool_use'; id: string; - name: 'code_execution' | 'web_fetch' | 'web_search'; + name: + | 'web_fetch' + | 'web_search' + // code execution 20250522: + | 'code_execution' + // code execution 20250825: + | 'bash_code_execution' + | 'text_editor_code_execution'; input: unknown; cache_control: AnthropicCacheControl | undefined; } @@ -128,6 +137,7 @@ export interface AnthropicWebSearchToolResultContent { cache_control: AnthropicCacheControl | undefined; } +// code execution results for code_execution_20250522 tool: export interface AnthropicCodeExecutionToolResultContent { type: 'code_execution_tool_result'; tool_use_id: string; @@ -140,6 +150,60 @@ export interface AnthropicCodeExecutionToolResultContent { cache_control: AnthropicCacheControl | undefined; } +// text editor code execution results for code_execution_20250825 tool: +export interface AnthropicTextEditorCodeExecutionToolResultContent { + type: 'text_editor_code_execution_tool_result'; + tool_use_id: string; + content: + | { + type: 'text_editor_code_execution_tool_result_error'; + error_code: string; + } + | { + type: 'text_editor_code_execution_create_result'; + is_file_update: boolean; + } + | { + type: 'text_editor_code_execution_view_result'; + content: string; + file_type: string; + num_lines: number | null; + start_line: number | null; + total_lines: number | null; + } + | { + type: 'text_editor_code_execution_str_replace_result'; + lines: string[] | null; + new_lines: number | null; + new_start: number | null; + old_lines: number | null; + old_start: number | null; + }; + cache_control: AnthropicCacheControl | undefined; +} + +// bash code execution results for code_execution_20250825 tool: +export interface AnthropicBashCodeExecutionToolResultContent { + type: 'bash_code_execution_tool_result'; + tool_use_id: string; + content: + | { + type: 'bash_code_execution_result'; + stdout: string; + stderr: string; + return_code: number; + content: { + type: 'bash_code_execution_output'; + file_id: string; + }[]; + } + | { + type: 'bash_code_execution_tool_result_error'; + error_code: string; + }; + cache_control: AnthropicCacheControl | undefined; +} + export interface AnthropicWebFetchToolResultContent { type: 'web_fetch_tool_result'; tool_use_id: string; @@ -170,6 +234,10 @@ export type AnthropicTool = type: 'code_execution_20250522'; name: string; } + | { + type: 'code_execution_20250825'; + name: string; + } | { name: string; type: 'computer_20250124' | 'computer_20241022'; @@ -329,6 +397,7 @@ export const anthropicMessagesResponseSchema = lazySchema(() => }), ]), }), + // code execution results for code_execution_20250522 tool: z.object({ type: z.literal('code_execution_tool_result'), tool_use_id: z.string(), @@ -345,6 +414,62 @@ export const anthropicMessagesResponseSchema = lazySchema(() => }), ]), }), + // bash code execution results for code_execution_20250825 tool: + z.object({ + type: z.literal('bash_code_execution_tool_result'), + tool_use_id: z.string(), + content: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('bash_code_execution_result'), + content: z.array( + z.object({ + type: z.literal('bash_code_execution_output'), + file_id: z.string(), + }), + ), + stdout: z.string(), + stderr: z.string(), + return_code: z.number(), + }), + z.object({ + type: z.literal('bash_code_execution_tool_result_error'), + error_code: z.string(), + }), + ]), + }), + // text editor code execution results for code_execution_20250825 tool: + z.object({ + type: z.literal('text_editor_code_execution_tool_result'), + tool_use_id: z.string(), + content: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('text_editor_code_execution_tool_result_error'), + error_code: z.string(), + }), + z.object({ + type: z.literal('text_editor_code_execution_view_result'), + content: z.string(), + file_type: z.string(), + num_lines: z.number().nullable(), + start_line: z.number().nullable(), + total_lines: z.number().nullable(), + }), + z.object({ + type: z.literal('text_editor_code_execution_create_result'), + is_file_update: z.boolean(), + }), + z.object({ + type: z.literal( + 'text_editor_code_execution_str_replace_result', + ), + lines: z.array(z.string()).nullable(), + new_lines: z.number().nullable(), + new_start: z.number().nullable(), + old_lines: z.number().nullable(), + old_start: z.number().nullable(), + }), + ]), + }), ]), ), stop_reason: z.string().nullish(), @@ -447,6 +572,7 @@ export const anthropicMessagesChunkSchema = lazySchema(() => }), ]), }), + // code execution results for code_execution_20250522 tool: z.object({ type: z.literal('code_execution_tool_result'), tool_use_id: z.string(), @@ -463,6 +589,62 @@ export const anthropicMessagesChunkSchema = lazySchema(() => }), ]), }), + // bash code execution results for code_execution_20250825 tool: + z.object({ + type: z.literal('bash_code_execution_tool_result'), + tool_use_id: z.string(), + content: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('bash_code_execution_result'), + content: z.array( + z.object({ + type: z.literal('bash_code_execution_output'), + file_id: z.string(), + }), + ), + stdout: z.string(), + stderr: z.string(), + return_code: z.number(), + }), + z.object({ + type: z.literal('bash_code_execution_tool_result_error'), + error_code: z.string(), + }), + ]), + }), + // text editor code execution results for code_execution_20250825 tool: + z.object({ + type: z.literal('text_editor_code_execution_tool_result'), + tool_use_id: z.string(), + content: z.discriminatedUnion('type', [ + z.object({ + type: z.literal('text_editor_code_execution_tool_result_error'), + error_code: z.string(), + }), + z.object({ + type: z.literal('text_editor_code_execution_view_result'), + content: z.string(), + file_type: z.string(), + num_lines: z.number().nullable(), + start_line: z.number().nullable(), + total_lines: z.number().nullable(), + }), + z.object({ + type: z.literal('text_editor_code_execution_create_result'), + is_file_update: z.boolean(), + }), + z.object({ + type: z.literal( + 'text_editor_code_execution_str_replace_result', + ), + lines: z.array(z.string()).nullable(), + new_lines: z.number().nullable(), + new_start: z.number().nullable(), + old_lines: z.number().nullable(), + old_start: z.number().nullable(), + }), + ]), + }), ]), }), z.object({ diff --git a/packages/anthropic/src/anthropic-messages-language-model.test.ts b/packages/anthropic/src/anthropic-messages-language-model.test.ts index 72b75db62e23..9dc22b688d26 100644 --- a/packages/anthropic/src/anthropic-messages-language-model.test.ts +++ b/packages/anthropic/src/anthropic-messages-language-model.test.ts @@ -1651,7 +1651,67 @@ describe('AnthropicMessagesLanguageModel', () => { }); }); - describe('code execution', () => { + describe('code execution 20250825', () => { + it('should send request body with include and tool', async () => { + prepareJsonFixtureResponse('anthropic-code-execution-20250825.1'); + + await model.doGenerate({ + prompt: TEST_PROMPT, + tools: [ + { + type: 'provider-defined', + id: 'anthropic.code_execution_20250825', + name: 'code_execution', + args: {}, + }, + ], + }); + + expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(` + { + "max_tokens": 4096, + "messages": [ + { + "content": [ + { + "text": "Hello", + "type": "text", + }, + ], + "role": "user", + }, + ], + "model": "claude-3-haiku-20240307", + "tools": [ + { + "name": "code_execution", + "type": "code_execution_20250825", + }, + ], + } + `); + }); + + it('should include code execution tool call and result in content', async () => { + prepareJsonFixtureResponse('anthropic-code-execution-20250825.1'); + + const result = await model.doGenerate({ + prompt: TEST_PROMPT, + tools: [ + { + type: 'provider-defined', + id: 'anthropic.code_execution_20250825', + name: 'code_execution', + args: {}, + }, + ], + }); + + expect(result.content).toMatchSnapshot(); + }); + }); + + describe('code execution 20250522', () => { const TEST_PROMPT = [ { role: 'user' as const, @@ -2018,11 +2078,6 @@ describe('AnthropicMessagesLanguageModel', () => { "id": "1", "type": "text-start", }, - { - "delta": "", - "id": "1", - "type": "text-delta", - }, { "delta": "{"value", "id": "1", @@ -2472,11 +2527,6 @@ describe('AnthropicMessagesLanguageModel', () => { "toolName": "test-tool", "type": "tool-input-start", }, - { - "delta": "", - "id": "toolu_01DBsB4vvYLnBDzZ5rBSxSLs", - "type": "tool-input-delta", - }, { "delta": "{"value", "id": "toolu_01DBsB4vvYLnBDzZ5rBSxSLs", @@ -2508,6 +2558,7 @@ describe('AnthropicMessagesLanguageModel', () => { }, { "input": "{"value":"Sparkle Day"}", + "providerExecuted": undefined, "toolCallId": "toolu_01DBsB4vvYLnBDzZ5rBSxSLs", "toolName": "test-tool", "type": "tool-call", @@ -3201,6 +3252,27 @@ describe('AnthropicMessagesLanguageModel', () => { `); }); + describe('code execution 20250825 tool', () => { + it('should stream code execution tool results', async () => { + prepareChunksFixtureResponse('anthropic-code-execution-20250825.1'); + + const result = await model.doStream({ + prompt: TEST_PROMPT, + tools: [ + { + type: 'provider-defined', + id: 'anthropic.code_execution_20250825', + name: 'code_execution', + args: {}, + }, + ], + }); + expect( + await convertReadableStreamToArray(result.stream), + ).toMatchSnapshot(); + }); + }); + describe('web fetch tool', () => { describe('txt response', () => { let result: Awaited>; diff --git a/packages/anthropic/src/anthropic-messages-language-model.ts b/packages/anthropic/src/anthropic-messages-language-model.ts index c3bcf4a80bd7..dc9b4b2c20e4 100644 --- a/packages/anthropic/src/anthropic-messages-language-model.ts +++ b/packages/anthropic/src/anthropic-messages-language-model.ts @@ -39,6 +39,7 @@ import { import { prepareTools } from './anthropic-prepare-tools'; import { convertToAnthropicMessagesPrompt } from './convert-to-anthropic-messages-prompt'; import { mapAnthropicStopReason } from './map-anthropic-stop-reason'; +import { codeExecution_20250825OutputSchema } from './tool/code-execution_20250825'; function createCitationSource( citation: Citation, @@ -461,7 +462,19 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { break; } case 'server_tool_use': { + // code execution 20250825 needs mapping: if ( + part.name === 'text_editor_code_execution' || + part.name === 'bash_code_execution' + ) { + content.push({ + type: 'tool-call', + toolCallId: part.id, + toolName: 'code_execution', + input: JSON.stringify({ type: part.name, ...part.input }), + providerExecuted: true, + }); + } else if ( part.name === 'web_search' || part.name === 'code_execution' || part.name === 'web_fetch' @@ -560,6 +573,8 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { } break; } + + // code execution 20250522: case 'code_execution_tool_result': { if (part.content.type === 'code_execution_result') { content.push({ @@ -589,6 +604,19 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { } break; } + + // code execution 20250825: + case 'bash_code_execution_tool_result': + case 'text_editor_code_execution_tool_result': { + content.push({ + type: 'tool-result', + toolCallId: part.tool_use_id, + toolName: 'code_execution', + result: part.content, + providerExecuted: true, + }); + break; + } } } @@ -661,6 +689,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { toolName: string; input: string; providerExecuted?: boolean; + firstDelta: boolean; } | { type: 'text' | 'reasoning' } > = {}; @@ -678,6 +707,8 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { | 'web_fetch_tool_result' | 'web_search_tool_result' | 'code_execution_tool_result' + | 'text_editor_code_execution_tool_result' + | 'bash_code_execution_tool_result' | undefined = undefined; const generateId = this.generateId; @@ -755,6 +786,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { toolCallId: value.content_block.id, toolName: value.content_block.name, input: '', + firstDelta: true, }; controller.enqueue( @@ -771,9 +803,16 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { case 'server_tool_use': { if ( - value.content_block.name === 'web_fetch' || - value.content_block.name === 'web_search' || - value.content_block.name === 'code_execution' + [ + 'web_fetch', + 'web_search', + // code execution 20250825: + 'code_execution', + // code execution 20250825 text editor: + 'text_editor_code_execution', + // code execution 20250825 bash: + 'bash_code_execution', + ].includes(value.content_block.name) ) { contentBlocks[value.index] = { type: 'tool-call', @@ -781,11 +820,21 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { toolName: value.content_block.name, input: '', providerExecuted: true, + firstDelta: true, }; + + // map tool names for the code execution 20250825 tool: + const mappedToolName = + value.content_block.name === + 'text_editor_code_execution' || + value.content_block.name === 'bash_code_execution' + ? 'code_execution' + : value.content_block.name; + controller.enqueue({ type: 'tool-input-start', id: value.content_block.id, - toolName: value.content_block.name, + toolName: mappedToolName, providerExecuted: true, }); } @@ -884,6 +933,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { return; } + // code execution 20250522: case 'code_execution_tool_result': { const part = value.content_block; @@ -919,6 +969,20 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { return; } + // code execution 20250825: + case 'bash_code_execution_tool_result': + case 'text_editor_code_execution_tool_result': { + const part = value.content_block; + controller.enqueue({ + type: 'tool-result', + toolCallId: part.tool_use_id, + toolName: 'code_execution', + result: part.content, + providerExecuted: true, + }); + return; + } + default: { const _exhaustiveCheck: never = contentBlockType; throw new Error( @@ -958,7 +1022,22 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { type: 'tool-input-end', id: contentBlock.toolCallId, }); - controller.enqueue(contentBlock); + + // map tool names for the code execution 20250825 tool: + const toolName = + contentBlock.toolName === + 'text_editor_code_execution' || + contentBlock.toolName === 'bash_code_execution' + ? 'code_execution' + : contentBlock.toolName; + + controller.enqueue({ + type: 'tool-call', + toolCallId: contentBlock.toolCallId, + toolName, + input: contentBlock.input, + providerExecuted: contentBlock.providerExecuted, + }); } break; } @@ -1020,7 +1099,13 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { case 'input_json_delta': { const contentBlock = contentBlocks[value.index]; - const delta = value.delta.partial_json; + let delta = value.delta.partial_json; + + // skip empty deltas to enable replacing the first character + // in the code execution 20250825 tool. + if (delta.length === 0) { + return; + } if (usesJsonResponseTool) { if (contentBlock?.type !== 'text') { @@ -1037,6 +1122,17 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { return; } + // for the code execution 20250825, we need to add + // the type to the delta and change the tool name. + if ( + contentBlock.firstDelta && + (contentBlock.toolName === 'bash_code_execution' || + contentBlock.toolName === + 'text_editor_code_execution') + ) { + delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`; + } + controller.enqueue({ type: 'tool-input-delta', id: contentBlock.toolCallId, @@ -1044,6 +1140,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 { }); contentBlock.input += delta; + contentBlock.firstDelta = false; } return; diff --git a/packages/anthropic/src/anthropic-prepare-tools.ts b/packages/anthropic/src/anthropic-prepare-tools.ts index 130de75aa970..d5a71e323fd0 100644 --- a/packages/anthropic/src/anthropic-prepare-tools.ts +++ b/packages/anthropic/src/anthropic-prepare-tools.ts @@ -60,6 +60,14 @@ export async function prepareTools({ }); break; } + case 'anthropic.code_execution_20250825': { + betas.add('code-execution-2025-08-25'); + anthropicTools.push({ + type: 'code_execution_20250825', + name: 'code_execution', + }); + break; + } case 'anthropic.computer_20250124': { betas.add('computer-use-2025-01-24'); anthropicTools.push({ diff --git a/packages/anthropic/src/anthropic-tools.ts b/packages/anthropic/src/anthropic-tools.ts index 75cd8abc27c9..2b578d06f4bd 100644 --- a/packages/anthropic/src/anthropic-tools.ts +++ b/packages/anthropic/src/anthropic-tools.ts @@ -1,6 +1,7 @@ import { bash_20241022 } from './tool/bash_20241022'; import { bash_20250124 } from './tool/bash_20250124'; import { codeExecution_20250522 } from './tool/code-execution_20250522'; +import { codeExecution_20250825 } from './tool/code-execution_20250825'; import { computer_20241022 } from './tool/computer_20241022'; import { computer_20250124 } from './tool/computer_20250124'; import { textEditor_20241022 } from './tool/text-editor_20241022'; @@ -43,6 +44,20 @@ export const anthropicTools = { */ codeExecution_20250522, + /** + * Claude can analyze data, create visualizations, perform complex calculations, + * run system commands, create and edit files, and process uploaded files directly within + * the API conversation. + * + * The code execution tool allows Claude to run both Python and Bash commands and manipulate files, + * including writing code, in a secure, sandboxed environment. + * + * This is the latest version with enhanced Bash support and file operations. + * + * Tool name must be `code_execution`. + */ + codeExecution_20250825, + /** * Claude can interact with computer environments through the computer use tool, which * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction. diff --git a/packages/anthropic/src/convert-to-anthropic-messages-prompt.test.ts b/packages/anthropic/src/convert-to-anthropic-messages-prompt.test.ts index 0e5a4a1d17d7..e612d102efb1 100644 --- a/packages/anthropic/src/convert-to-anthropic-messages-prompt.test.ts +++ b/packages/anthropic/src/convert-to-anthropic-messages-prompt.test.ts @@ -1086,44 +1086,45 @@ describe('assistant messages', () => { expect(warnings).toMatchInlineSnapshot(`[]`); }); - it('should convert anthropic code_execution tool call and result parts', async () => { - const warnings: LanguageModelV3CallWarning[] = []; - const result = await convertToAnthropicMessagesPrompt({ - prompt: [ - { - role: 'assistant', - content: [ - { - input: { - code: 'print("Hello, world!")', + describe('code_execution 20250522', () => { + it('should convert anthropic code_execution tool call and result parts', async () => { + const warnings: LanguageModelV3CallWarning[] = []; + const result = await convertToAnthropicMessagesPrompt({ + prompt: [ + { + role: 'assistant', + content: [ + { + input: { + code: 'print("Hello, world!")', + }, + providerExecuted: true, + toolCallId: 'srvtoolu_01XyZ1234567890', + toolName: 'code_execution', + type: 'tool-call', }, - providerExecuted: true, - toolCallId: 'srvtoolu_01XyZ1234567890', - toolName: 'code_execution', - type: 'tool-call', - }, - { - output: { - type: 'json', - value: { - type: 'code_execution_result', - stdout: 'Hello, world!', - stderr: '', - return_code: 0, + { + output: { + type: 'json', + value: { + type: 'code_execution_result', + stdout: 'Hello, world!', + stderr: '', + return_code: 0, + }, }, + toolCallId: 'srvtoolu_01XyZ1234567890', + toolName: 'code_execution', + type: 'tool-result', }, - toolCallId: 'srvtoolu_01XyZ1234567890', - toolName: 'code_execution', - type: 'tool-result', - }, - ], - }, - ], - sendReasoning: false, - warnings, - }); + ], + }, + ], + sendReasoning: false, + warnings, + }); - expect(result).toMatchInlineSnapshot(` + expect(result).toMatchInlineSnapshot(` { "betas": Set {}, "prompt": { @@ -1158,7 +1159,135 @@ describe('assistant messages', () => { }, } `); - expect(warnings).toMatchInlineSnapshot(`[]`); + expect(warnings).toMatchInlineSnapshot(`[]`); + }); + }); + + describe('code_execution 20250825', () => { + it('should convert anthropic code_execution tool call and result parts', async () => { + const warnings: LanguageModelV3CallWarning[] = []; + const result = await convertToAnthropicMessagesPrompt({ + prompt: [ + { + role: 'assistant', + content: [ + { + type: 'tool-call', + toolCallId: 'srvtoolu_01Hq9rR6fZwwDGHkTYRafn7k', + toolName: 'code_execution', + input: { + type: 'text_editor_code_execution', + command: 'create', + path: '/tmp/fibonacci.py', + file_text: 'def..', + }, + providerExecuted: true, + }, + { + type: 'tool-result', + toolCallId: 'srvtoolu_01Hq9rR6fZwwDGHkTYRafn7k', + toolName: 'code_execution', + output: { + type: 'json', + value: { + type: 'text_editor_code_execution_create_result', + is_file_update: false, + }, + }, + }, + { + type: 'tool-call', + toolCallId: 'srvtoolu_0193G3ttnkiTfZASwHQSKc2V', + toolName: 'code_execution', + input: { + type: 'bash_code_execution', + command: 'python /tmp/fibonacci.py', + }, + providerExecuted: true, + }, + { + type: 'tool-result', + toolCallId: 'srvtoolu_0193G3ttnkiTfZASwHQSKc2V', + toolName: 'code_execution', + output: { + type: 'json', + value: { + type: 'bash_code_execution_result', + content: [], + stdout: 'The 10th Fibonacci number is: 34\n', + stderr: '', + return_code: 0, + }, + }, + }, + ], + }, + ], + sendReasoning: false, + warnings, + }); + + expect(result).toMatchInlineSnapshot(` + { + "betas": Set {}, + "prompt": { + "messages": [ + { + "content": [ + { + "cache_control": undefined, + "id": "srvtoolu_01Hq9rR6fZwwDGHkTYRafn7k", + "input": { + "command": "create", + "file_text": "def..", + "path": "/tmp/fibonacci.py", + "type": "text_editor_code_execution", + }, + "name": "text_editor_code_execution", + "type": "server_tool_use", + }, + { + "cache_control": undefined, + "content": { + "is_file_update": false, + "type": "text_editor_code_execution_create_result", + }, + "tool_use_id": "srvtoolu_01Hq9rR6fZwwDGHkTYRafn7k", + "type": "text_editor_code_execution_tool_result", + }, + { + "cache_control": undefined, + "id": "srvtoolu_0193G3ttnkiTfZASwHQSKc2V", + "input": { + "command": "python /tmp/fibonacci.py", + "type": "bash_code_execution", + }, + "name": "bash_code_execution", + "type": "server_tool_use", + }, + { + "cache_control": undefined, + "content": { + "content": [], + "return_code": 0, + "stderr": "", + "stdout": "The 10th Fibonacci number is: 34 + ", + "type": "bash_code_execution_result", + }, + "tool_use_id": "srvtoolu_0193G3ttnkiTfZASwHQSKc2V", + "type": "bash_code_execution_tool_result", + }, + ], + "role": "assistant", + }, + ], + "system": undefined, + }, + } + `); + expect(warnings).toMatchInlineSnapshot(`[]`); + }); }); }); diff --git a/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts b/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts index ab69ea82e426..4b4c15baddf8 100644 --- a/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts +++ b/packages/anthropic/src/convert-to-anthropic-messages-prompt.ts @@ -22,6 +22,7 @@ import { import { anthropicFilePartProviderOptions } from './anthropic-messages-options'; import { getCacheControl } from './get-cache-control'; import { codeExecution_20250522OutputSchema } from './tool/code-execution_20250522'; +import { codeExecution_20250825OutputSchema } from './tool/code-execution_20250825'; import { webFetch_20250910OutputSchema } from './tool/web-fetch-20250910'; import { webSearch_20250305OutputSchema } from './tool/web-search_20250305'; @@ -424,8 +425,25 @@ export async function convertToAnthropicMessagesPrompt({ case 'tool-call': { if (part.providerExecuted) { + // code execution 20250825: if ( - part.toolName === 'code_execution' || + part.toolName === 'code_execution' && + part.input != null && + typeof part.input === 'object' && + 'type' in part.input && + typeof part.input.type === 'string' && + (part.input.type === 'bash_code_execution' || + part.input.type === 'text_editor_code_execution') + ) { + anthropicContent.push({ + type: 'server_tool_use', + id: part.toolCallId, + name: part.input.type, // map back to subtool name + input: part.input, + cache_control: cacheControl, + }); + } else if ( + part.toolName === 'code_execution' || // code execution 20250522 part.toolName === 'web_fetch' || part.toolName === 'web_search' ) { @@ -469,23 +487,65 @@ export async function convertToAnthropicMessagesPrompt({ break; } - const codeExecutionOutput = await validateTypes({ - value: output.value, - schema: codeExecution_20250522OutputSchema, - }); + if ( + output.value == null || + typeof output.value !== 'object' || + !('type' in output.value) || + typeof output.value.type !== 'string' + ) { + warnings.push({ + type: 'other', + message: `provider executed tool result output value is not a valid code execution result for tool ${part.toolName}`, + }); + break; + } - anthropicContent.push({ - type: 'code_execution_tool_result', - tool_use_id: part.toolCallId, - content: { - type: codeExecutionOutput.type, - stdout: codeExecutionOutput.stdout, - stderr: codeExecutionOutput.stderr, - return_code: codeExecutionOutput.return_code, - }, - cache_control: cacheControl, - }); + // to distinguish between code execution 20250522 and 20250825, + // we check if a type property is present in the output.value + if (output.value.type === 'code_execution_result') { + // code execution 20250522 + const codeExecutionOutput = await validateTypes({ + value: output.value, + schema: codeExecution_20250522OutputSchema, + }); + + anthropicContent.push({ + type: 'code_execution_tool_result', + tool_use_id: part.toolCallId, + content: { + type: codeExecutionOutput.type, + stdout: codeExecutionOutput.stdout, + stderr: codeExecutionOutput.stderr, + return_code: codeExecutionOutput.return_code, + }, + cache_control: cacheControl, + }); + } else { + // code execution 20250825 + const codeExecutionOutput = await validateTypes({ + value: output.value, + schema: codeExecution_20250825OutputSchema, + }); + anthropicContent.push( + codeExecutionOutput.type === + 'bash_code_execution_result' || + codeExecutionOutput.type === + 'bash_code_execution_tool_result_error' + ? { + type: 'bash_code_execution_tool_result', + tool_use_id: part.toolCallId, + cache_control: cacheControl, + content: codeExecutionOutput, + } + : { + type: 'text_editor_code_execution_tool_result', + tool_use_id: part.toolCallId, + cache_control: cacheControl, + content: codeExecutionOutput, + }, + ); + } break; } diff --git a/packages/anthropic/src/tool/code-execution_20250825.ts b/packages/anthropic/src/tool/code-execution_20250825.ts new file mode 100644 index 000000000000..b4471bbcd153 --- /dev/null +++ b/packages/anthropic/src/tool/code-execution_20250825.ts @@ -0,0 +1,215 @@ +import { + createProviderDefinedToolFactoryWithOutputSchema, + lazySchema, + zodSchema, +} from '@ai-sdk/provider-utils'; +import { z } from 'zod/v4'; + +export const codeExecution_20250825OutputSchema = lazySchema(() => + zodSchema( + z.discriminatedUnion('type', [ + z.object({ + type: z.literal('bash_code_execution_result'), + content: z.array( + z.object({ + type: z.literal('bash_code_execution_output'), + file_id: z.string(), + }), + ), + stdout: z.string(), + stderr: z.string(), + return_code: z.number(), + }), + z.object({ + type: z.literal('bash_code_execution_tool_result_error'), + error_code: z.string(), + }), + z.object({ + type: z.literal('text_editor_code_execution_tool_result_error'), + error_code: z.string(), + }), + z.object({ + type: z.literal('text_editor_code_execution_view_result'), + content: z.string(), + file_type: z.string(), + num_lines: z.number().nullable(), + start_line: z.number().nullable(), + total_lines: z.number().nullable(), + }), + z.object({ + type: z.literal('text_editor_code_execution_create_result'), + is_file_update: z.boolean(), + }), + z.object({ + type: z.literal('text_editor_code_execution_str_replace_result'), + lines: z.array(z.string()).nullable(), + new_lines: z.number().nullable(), + new_start: z.number().nullable(), + old_lines: z.number().nullable(), + old_start: z.number().nullable(), + }), + ]), + ), +); + +export const codeExecution_20250825InputSchema = lazySchema(() => + zodSchema( + z.discriminatedUnion('type', [ + z.object({ + type: z.literal('bash_code_execution'), + command: z.string(), + }), + z.discriminatedUnion('command', [ + z.object({ + type: z.literal('text_editor_code_execution'), + command: z.literal('view'), + path: z.string(), + }), + z.object({ + type: z.literal('text_editor_code_execution'), + command: z.literal('create'), + path: z.string(), + file_text: z.string().nullish(), + }), + z.object({ + type: z.literal('text_editor_code_execution'), + command: z.literal('str_replace'), + path: z.string(), + old_str: z.string(), + new_str: z.string(), + }), + ]), + ]), + ), +); + +const factory = createProviderDefinedToolFactoryWithOutputSchema< + | { + type: 'bash_code_execution'; + + /** + * Shell command to execute. + */ + command: string; + } + | { + type: 'text_editor_code_execution'; + command: 'view'; + + /** + * The path to the file to view. + */ + path: string; + } + | { + type: 'text_editor_code_execution'; + command: 'create'; + + /** + * The path to the file to edit. + */ + path: string; + + /** + * The text of the file to edit. + */ + file_text?: string | null; + } + | { + type: 'text_editor_code_execution'; + command: 'str_replace'; + + /** + * The path to the file to edit. + */ + path: string; + + /** + * The string to replace. + */ + old_str: string; + + /** + * The new string to replace the old string with. + */ + new_str: string; + }, + | { + type: 'bash_code_execution_result'; + + /** + * Output from successful execution + */ + stdout: string; + + /** + * Error messages if execution fails + */ + stderr: string; + + /** + * 0 for success, non-zero for failure + */ + return_code: number; + } + | { + type: 'bash_code_execution_tool_result_error'; + + /** + * Available options: invalid_tool_input, unavailable, too_many_requests, + * execution_time_exceeded, output_file_too_large. + */ + error_code: string; + } + | { + type: 'text_editor_code_execution_tool_result_error'; + + /** + * Available options: invalid_tool_input, unavailable, too_many_requests, + * execution_time_exceeded, file_not_found. + */ + error_code: string; + } + | { + type: 'text_editor_code_execution_view_result'; + + content: string; + + /** + * The type of the file. Available options: text, image, pdf. + */ + file_type: string; + + num_lines: number | null; + start_line: number | null; + total_lines: number | null; + } + | { + type: 'text_editor_code_execution_create_result'; + + is_file_update: boolean; + } + | { + type: 'text_editor_code_execution_str_replace_result'; + + lines: string[] | null; + new_lines: number | null; + new_start: number | null; + old_lines: number | null; + old_start: number | null; + }, + { + // no arguments + } +>({ + id: 'anthropic.code_execution_20250825', + name: 'code_execution', + inputSchema: codeExecution_20250825InputSchema, + outputSchema: codeExecution_20250825OutputSchema, +}); + +export const codeExecution_20250825 = ( + args: Parameters[0] = {}, +) => { + return factory(args); +};