|
970 | 970 | "source": [ |
971 | 971 | "### In tool results (agentic RAG)\n", |
972 | 972 | "\n", |
973 | | - ":::info Requires ``langchain-anthropic>=0.3.17``\n", |
974 | | - "\n", |
| 973 | + ":::info\n", |
| 974 | + "Requires ``langchain-anthropic>=0.3.17``\n", |
975 | 975 | ":::\n", |
976 | 976 | "\n", |
977 | 977 | "Claude supports a [search_result](https://docs.anthropic.com/en/docs/build-with-claude/search-results) content block representing citable results from queries against a knowledge base or other custom source. These content blocks can be passed to claude both top-line (as in the above example) and within a tool result. This allows Claude to cite elements of its response using the result of a tool call.\n", |
|
1290 | 1290 | "print(f\"Key Points: {result.key_points}\")" |
1291 | 1291 | ] |
1292 | 1292 | }, |
| 1293 | + { |
| 1294 | + "cell_type": "markdown", |
| 1295 | + "id": "c580c20a", |
| 1296 | + "metadata": {}, |
| 1297 | + "source": [ |
| 1298 | + "### Web fetching\n", |
| 1299 | + "\n", |
| 1300 | + "Claude can use a [web fetching tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/web-fetch-tool) to run searches and ground its responses with citations." |
| 1301 | + ] |
| 1302 | + }, |
| 1303 | + { |
| 1304 | + "cell_type": "markdown", |
| 1305 | + "id": "5cf6ad08", |
| 1306 | + "metadata": {}, |
| 1307 | + "source": [ |
| 1308 | + ":::info\n", |
| 1309 | + "Web search tool is supported since ``langchain-anthropic>=0.3.20``\n", |
| 1310 | + ":::" |
| 1311 | + ] |
| 1312 | + }, |
| 1313 | + { |
| 1314 | + "cell_type": "code", |
| 1315 | + "execution_count": null, |
| 1316 | + "id": "c4804be1", |
| 1317 | + "metadata": {}, |
| 1318 | + "outputs": [], |
| 1319 | + "source": [ |
| 1320 | + "from langchain_anthropic import ChatAnthropic\n", |
| 1321 | + "\n", |
| 1322 | + "llm = ChatAnthropic(\n", |
| 1323 | + " model=\"claude-3-5-haiku-latest\",\n", |
| 1324 | + " betas=[\"web-fetch-2025-09-10\"], # Enable web fetch beta\n", |
| 1325 | + ")\n", |
| 1326 | + "\n", |
| 1327 | + "tool = {\"type\": \"web_fetch_20250910\", \"name\": \"web_fetch\", \"max_uses\": 3}\n", |
| 1328 | + "llm_with_tools = llm.bind_tools([tool])\n", |
| 1329 | + "\n", |
| 1330 | + "response = llm_with_tools.invoke(\n", |
| 1331 | + " \"Please analyze the content at https://example.com/article\"\n", |
| 1332 | + ")" |
| 1333 | + ] |
| 1334 | + }, |
| 1335 | + { |
| 1336 | + "cell_type": "markdown", |
| 1337 | + "id": "088c41d0", |
| 1338 | + "metadata": {}, |
| 1339 | + "source": [ |
| 1340 | + ":::warning\n", |
| 1341 | + "Note: you must add the `'web-fetch-2025-09-10'` beta header to use this tool.\n", |
| 1342 | + ":::" |
| 1343 | + ] |
| 1344 | + }, |
1293 | 1345 | { |
1294 | 1346 | "cell_type": "markdown", |
1295 | 1347 | "id": "1478cdc6-2e52-4870-80f9-b4ddf88f2db2", |
|
1299 | 1351 | "\n", |
1300 | 1352 | "Claude can use a [code execution tool](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/code-execution-tool) to execute Python code in a sandboxed environment.\n", |
1301 | 1353 | "\n", |
1302 | | - ":::info Code execution is supported since ``langchain-anthropic>=0.3.14``\n", |
1303 | | - "\n", |
| 1354 | + ":::info\n", |
| 1355 | + "Code execution is supported since ``langchain-anthropic>=0.3.14``\n", |
1304 | 1356 | ":::" |
1305 | 1357 | ] |
1306 | 1358 | }, |
1307 | 1359 | { |
1308 | 1360 | "cell_type": "code", |
1309 | | - "execution_count": 1, |
| 1361 | + "execution_count": null, |
1310 | 1362 | "id": "2ce13632-a2da-439f-a429-f66481501630", |
1311 | 1363 | "metadata": {}, |
1312 | 1364 | "outputs": [], |
|
1315 | 1367 | "\n", |
1316 | 1368 | "llm = ChatAnthropic(\n", |
1317 | 1369 | " model=\"claude-sonnet-4-20250514\",\n", |
1318 | | - " betas=[\"code-execution-2025-05-22\"],\n", |
| 1370 | + " betas=[\"code-execution-2025-05-22\"], # Enable code execution beta\n", |
1319 | 1371 | ")\n", |
1320 | 1372 | "\n", |
1321 | 1373 | "tool = {\"type\": \"code_execution_20250522\", \"name\": \"code_execution\"}\n", |
|
1326 | 1378 | ")" |
1327 | 1379 | ] |
1328 | 1380 | }, |
| 1381 | + { |
| 1382 | + "cell_type": "markdown", |
| 1383 | + "id": "a6b5e15a", |
| 1384 | + "metadata": {}, |
| 1385 | + "source": [ |
| 1386 | + ":::warning\n", |
| 1387 | + "Note: you must add the `'code_execution_20250522'` beta header to use this tool.\n", |
| 1388 | + ":::" |
| 1389 | + ] |
| 1390 | + }, |
1329 | 1391 | { |
1330 | 1392 | "cell_type": "markdown", |
1331 | 1393 | "id": "24076f91-3a3d-4e53-9618-429888197061", |
|
1404 | 1466 | "\n", |
1405 | 1467 | "Claude can use a [MCP connector tool](https://docs.anthropic.com/en/docs/agents-and-tools/mcp-connector) for model-generated calls to remote MCP servers.\n", |
1406 | 1468 | "\n", |
1407 | | - ":::info Remote MCP is supported since ``langchain-anthropic>=0.3.14``\n", |
1408 | | - "\n", |
| 1469 | + ":::info\n", |
| 1470 | + "Remote MCP is supported since ``langchain-anthropic>=0.3.14``\n", |
1409 | 1471 | ":::" |
1410 | 1472 | ] |
1411 | 1473 | }, |
1412 | 1474 | { |
1413 | 1475 | "cell_type": "code", |
1414 | | - "execution_count": 1, |
| 1476 | + "execution_count": null, |
1415 | 1477 | "id": "22fc4a89-e6d8-4615-96cb-2e117349aebf", |
1416 | 1478 | "metadata": {}, |
1417 | 1479 | "outputs": [], |
|
1423 | 1485 | " \"type\": \"url\",\n", |
1424 | 1486 | " \"url\": \"https://mcp.deepwiki.com/mcp\",\n", |
1425 | 1487 | " \"name\": \"deepwiki\",\n", |
1426 | | - " \"tool_configuration\": { # optional configuration\n", |
| 1488 | + " \"tool_configuration\": { # Optional configuration\n", |
1427 | 1489 | " \"enabled\": True,\n", |
1428 | 1490 | " \"allowed_tools\": [\"ask_question\"],\n", |
1429 | 1491 | " },\n", |
1430 | | - " \"authorization_token\": \"PLACEHOLDER\", # optional authorization\n", |
| 1492 | + " \"authorization_token\": \"PLACEHOLDER\", # Optional authorization\n", |
1431 | 1493 | " }\n", |
1432 | 1494 | "]\n", |
1433 | 1495 | "\n", |
1434 | 1496 | "llm = ChatAnthropic(\n", |
1435 | 1497 | " model=\"claude-sonnet-4-20250514\",\n", |
1436 | | - " betas=[\"mcp-client-2025-04-04\"],\n", |
| 1498 | + " betas=[\"mcp-client-2025-04-04\"], # Enable MCP beta\n", |
1437 | 1499 | " mcp_servers=mcp_servers,\n", |
1438 | 1500 | ")\n", |
1439 | 1501 | "\n", |
|
1443 | 1505 | ")" |
1444 | 1506 | ] |
1445 | 1507 | }, |
| 1508 | + { |
| 1509 | + "cell_type": "markdown", |
| 1510 | + "id": "0d6d7197", |
| 1511 | + "metadata": {}, |
| 1512 | + "source": [ |
| 1513 | + ":::warning\n", |
| 1514 | + "Note: you must add the `'mcp-client-2025-04-04'` beta header to use this tool.\n", |
| 1515 | + ":::" |
| 1516 | + ] |
| 1517 | + }, |
1446 | 1518 | { |
1447 | 1519 | "cell_type": "markdown", |
1448 | 1520 | "id": "2fd5d545-a40d-42b1-ad0c-0a79e2536c9b", |
|
0 commit comments