-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(provider/anthropic): add code_execution_20250825 tool #9435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgrammel
merged 38 commits into
vercel:main
from
ellispinsky:feat/anthropic-code-execution-20250825
Oct 14, 2025
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5665543
feat(anthropic): update code execution tool to version 20250825 with …
ellispinsky 17cb21b
fix(anthropic): update version from minor to patch for code execution…
ellispinsky 081a508
Merge branch 'main' into feat/anthropic-code-execution-20250825
lgrammel d83114b
revert
lgrammel 8557448
docs
lgrammel ffcd948
docs
lgrammel c7e9414
fx
lgrammel 5065992
tool spec1
lgrammel 49f616a
spec2
lgrammel 51a5af9
types1
lgrammel 8c75b93
types2
lgrammel e067773
types3
lgrammel c37ef5d
types4
lgrammel c2d5f08
ex1
lgrammel 8187dc9
test1
lgrammel 61eb304
stream
lgrammel 89675a4
refactor
lgrammel 5d93678
ex2
lgrammel bd197cd
ex3
lgrammel 1f36110
test2
lgrammel 750cb6b
refactor
lgrammel d75166e
refactor
lgrammel 18750e5
generate
lgrammel f0f07ed
fix
lgrammel e427ee4
clean
lgrammel 72aef19
generate input
lgrammel b11fe09
input tool mapping
lgrammel 3be1418
no mapping
lgrammel 5ea0d0c
example4
lgrammel 3561362
example
lgrammel e028810
Merge branch 'main' into feat/anthropic-code-execution-20250825
lgrammel 7f94b32
clean
lgrammel 6c9275f
extract
lgrammel 50a5307
output mapping
lgrammel 4b843bb
map inputs back
lgrammel 722e642
types
lgrammel 251a3b0
view
lgrammel 442c0c5
view
lgrammel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/anthropic': minor | ||
--- | ||
|
||
Add support for 2025-08-25 code execution tool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
examples/ai-core/src/generate-text/anthropic-code-execution-latest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { anthropic } from '@ai-sdk/anthropic'; | ||
import { generateText } from 'ai'; | ||
import 'dotenv/config'; | ||
|
||
async function main() { | ||
// Using the latest code execution tool with enhanced Bash and file operation support | ||
const codeExecutionTool = anthropic.tools.codeExecution_20250825(); | ||
|
||
const result = await generateText({ | ||
model: anthropic('claude-opus-4-20250514'), | ||
prompt: | ||
'Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] using Python', | ||
tools: { | ||
code_execution: codeExecutionTool, | ||
}, | ||
}); | ||
|
||
console.log('Result:', result.text); | ||
console.log('\nTool Calls:', JSON.stringify(result.toolCalls, null, 2)); | ||
console.log('\nTool Results:', JSON.stringify(result.toolResults, null, 2)); | ||
} | ||
|
||
main().catch(console.error); |
53 changes: 53 additions & 0 deletions
53
examples/ai-core/src/stream-text/anthropic-code-execution-latest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { anthropic } from '@ai-sdk/anthropic'; | ||
import { streamText } from 'ai'; | ||
import 'dotenv/config'; | ||
|
||
async function main() { | ||
// Using the latest code execution tool with enhanced Bash and file operation support | ||
const codeExecutionTool = anthropic.tools.codeExecution_20250825(); | ||
|
||
const result = streamText({ | ||
model: anthropic('claude-opus-4-20250514'), | ||
prompt: | ||
'Write a Python script to calculate fibonacci numbers and then execute it to find the 10th fibonacci number', | ||
tools: { | ||
code_execution: codeExecutionTool, | ||
}, | ||
}); | ||
|
||
process.stdout.write('\nAssistant: '); | ||
|
||
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'); | ||
console.log('Finish reason:', await result.finishReason); | ||
console.log('Usage:', await result.usage); | ||
} | ||
|
||
main().catch(console.error); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.