opencode-skills-antigravity 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/bundled-skills/ad-creative/SKILL.md +371 -0
  2. package/bundled-skills/ad-creative/evals/evals.json +90 -0
  3. package/bundled-skills/ad-creative/references/generative-tools.md +637 -0
  4. package/bundled-skills/ad-creative/references/platform-specs.md +213 -0
  5. package/bundled-skills/ai-seo/SKILL.md +407 -0
  6. package/bundled-skills/ai-seo/evals/evals.json +90 -0
  7. package/bundled-skills/ai-seo/references/content-patterns.md +285 -0
  8. package/bundled-skills/ai-seo/references/platform-ranking-factors.md +152 -0
  9. package/bundled-skills/backend-dev-guidelines/SKILL.md +1 -1
  10. package/bundled-skills/cc-skill-security-review/SKILL.md +1 -1
  11. package/bundled-skills/churn-prevention/SKILL.md +433 -0
  12. package/bundled-skills/churn-prevention/evals/evals.json +93 -0
  13. package/bundled-skills/churn-prevention/references/cancel-flow-patterns.md +316 -0
  14. package/bundled-skills/churn-prevention/references/dunning-playbook.md +408 -0
  15. package/bundled-skills/claude-api/LICENSE.txt +202 -0
  16. package/bundled-skills/claude-api/SKILL.md +252 -0
  17. package/bundled-skills/claude-api/csharp/claude-api.md +70 -0
  18. package/bundled-skills/claude-api/curl/examples.md +164 -0
  19. package/bundled-skills/claude-api/go/claude-api.md +146 -0
  20. package/bundled-skills/claude-api/java/claude-api.md +128 -0
  21. package/bundled-skills/claude-api/php/claude-api.md +88 -0
  22. package/bundled-skills/claude-api/python/agent-sdk/README.md +269 -0
  23. package/bundled-skills/claude-api/python/agent-sdk/patterns.md +319 -0
  24. package/bundled-skills/claude-api/python/claude-api/README.md +404 -0
  25. package/bundled-skills/claude-api/python/claude-api/batches.md +182 -0
  26. package/bundled-skills/claude-api/python/claude-api/files-api.md +162 -0
  27. package/bundled-skills/claude-api/python/claude-api/streaming.md +162 -0
  28. package/bundled-skills/claude-api/python/claude-api/tool-use.md +587 -0
  29. package/bundled-skills/claude-api/ruby/claude-api.md +87 -0
  30. package/bundled-skills/claude-api/shared/error-codes.md +205 -0
  31. package/bundled-skills/claude-api/shared/live-sources.md +121 -0
  32. package/bundled-skills/claude-api/shared/models.md +68 -0
  33. package/bundled-skills/claude-api/shared/tool-use-concepts.md +305 -0
  34. package/bundled-skills/claude-api/typescript/agent-sdk/README.md +220 -0
  35. package/bundled-skills/claude-api/typescript/agent-sdk/patterns.md +150 -0
  36. package/bundled-skills/claude-api/typescript/claude-api/README.md +313 -0
  37. package/bundled-skills/claude-api/typescript/claude-api/batches.md +106 -0
  38. package/bundled-skills/claude-api/typescript/claude-api/files-api.md +98 -0
  39. package/bundled-skills/claude-api/typescript/claude-api/streaming.md +178 -0
  40. package/bundled-skills/claude-api/typescript/claude-api/tool-use.md +477 -0
  41. package/bundled-skills/codex-review/SKILL.md +1 -1
  42. package/bundled-skills/cold-email/SKILL.md +167 -0
  43. package/bundled-skills/cold-email/evals/evals.json +94 -0
  44. package/bundled-skills/cold-email/references/benchmarks.md +83 -0
  45. package/bundled-skills/cold-email/references/follow-up-sequences.md +81 -0
  46. package/bundled-skills/cold-email/references/frameworks.md +90 -0
  47. package/bundled-skills/cold-email/references/personalization.md +79 -0
  48. package/bundled-skills/cold-email/references/subject-lines.md +53 -0
  49. package/bundled-skills/content-strategy/SKILL.md +374 -0
  50. package/bundled-skills/content-strategy/evals/evals.json +90 -0
  51. package/bundled-skills/content-strategy/references/headless-cms.md +194 -0
  52. package/bundled-skills/context7-auto-research/SKILL.md +1 -1
  53. package/bundled-skills/dbos-golang/SKILL.md +1 -1
  54. package/bundled-skills/dbos-python/SKILL.md +1 -1
  55. package/bundled-skills/dbos-typescript/SKILL.md +1 -1
  56. package/bundled-skills/debug-buttercup/SKILL.md +1 -1
  57. package/bundled-skills/defuddle/SKILL.md +50 -0
  58. package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
  59. package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
  60. package/bundled-skills/docs/integrations/jetski-gemini-loader/package.json +1 -0
  61. package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
  62. package/bundled-skills/docs/maintainers/skills-import-2026-03-21.md +81 -0
  63. package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
  64. package/bundled-skills/docs/users/bundles.md +1 -1
  65. package/bundled-skills/docs/users/claude-code-skills.md +1 -1
  66. package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
  67. package/bundled-skills/docs/users/getting-started.md +1 -1
  68. package/bundled-skills/docs/users/kiro-integration.md +1 -1
  69. package/bundled-skills/docs/users/usage.md +4 -4
  70. package/bundled-skills/docs/users/visual-guide.md +4 -4
  71. package/bundled-skills/evaluation/SKILL.md +1 -1
  72. package/bundled-skills/exa-search/SKILL.md +1 -1
  73. package/bundled-skills/firecrawl-scraper/SKILL.md +1 -1
  74. package/bundled-skills/frontend-dev-guidelines/SKILL.md +1 -1
  75. package/bundled-skills/gha-security-review/SKILL.md +2 -1
  76. package/bundled-skills/git-pushing/SKILL.md +1 -1
  77. package/bundled-skills/internal-comms/LICENSE.txt +202 -0
  78. package/bundled-skills/internal-comms/SKILL.md +35 -0
  79. package/bundled-skills/internal-comms/examples/3p-updates.md +47 -0
  80. package/bundled-skills/internal-comms/examples/company-newsletter.md +65 -0
  81. package/bundled-skills/internal-comms/examples/faq-answers.md +30 -0
  82. package/bundled-skills/internal-comms/examples/general-comms.md +16 -0
  83. package/bundled-skills/json-canvas/SKILL.md +253 -0
  84. package/bundled-skills/json-canvas/references/EXAMPLES.md +329 -0
  85. package/bundled-skills/lead-magnets/SKILL.md +319 -0
  86. package/bundled-skills/lead-magnets/references/benchmarks.md +129 -0
  87. package/bundled-skills/lead-magnets/references/format-guide.md +196 -0
  88. package/bundled-skills/memory-systems/SKILL.md +1 -1
  89. package/bundled-skills/obsidian-bases/SKILL.md +506 -0
  90. package/bundled-skills/obsidian-bases/references/FUNCTIONS_REFERENCE.md +173 -0
  91. package/bundled-skills/obsidian-cli/SKILL.md +115 -0
  92. package/bundled-skills/obsidian-markdown/SKILL.md +205 -0
  93. package/bundled-skills/obsidian-markdown/references/CALLOUTS.md +58 -0
  94. package/bundled-skills/obsidian-markdown/references/EMBEDS.md +63 -0
  95. package/bundled-skills/obsidian-markdown/references/PROPERTIES.md +61 -0
  96. package/bundled-skills/product-marketing-context/SKILL.md +250 -0
  97. package/bundled-skills/product-marketing-context/evals/evals.json +85 -0
  98. package/bundled-skills/react-best-practices/SKILL.md +1 -1
  99. package/bundled-skills/revops/SKILL.md +352 -0
  100. package/bundled-skills/revops/evals/evals.json +91 -0
  101. package/bundled-skills/revops/references/automation-playbooks.md +290 -0
  102. package/bundled-skills/revops/references/lifecycle-definitions.md +278 -0
  103. package/bundled-skills/revops/references/routing-rules.md +203 -0
  104. package/bundled-skills/revops/references/scoring-models.md +247 -0
  105. package/bundled-skills/sales-enablement/SKILL.md +358 -0
  106. package/bundled-skills/sales-enablement/evals/evals.json +91 -0
  107. package/bundled-skills/sales-enablement/references/deck-frameworks.md +263 -0
  108. package/bundled-skills/sales-enablement/references/demo-scripts.md +355 -0
  109. package/bundled-skills/sales-enablement/references/objection-library.md +270 -0
  110. package/bundled-skills/sales-enablement/references/one-pager-templates.md +208 -0
  111. package/bundled-skills/seo/SKILL.md +139 -0
  112. package/bundled-skills/seo/references/cwv-thresholds.md +108 -0
  113. package/bundled-skills/seo/references/eeat-framework.md +214 -0
  114. package/bundled-skills/seo/references/quality-gates.md +155 -0
  115. package/bundled-skills/seo/references/schema-types.md +118 -0
  116. package/bundled-skills/seo-competitor-pages/SKILL.md +229 -0
  117. package/bundled-skills/seo-content/SKILL.md +186 -0
  118. package/bundled-skills/seo-dataforseo/SKILL.md +395 -0
  119. package/bundled-skills/seo-geo/SKILL.md +254 -0
  120. package/bundled-skills/seo-hreflang/SKILL.md +209 -0
  121. package/bundled-skills/seo-image-gen/SKILL.md +183 -0
  122. package/bundled-skills/seo-images/SKILL.md +193 -0
  123. package/bundled-skills/seo-page/SKILL.md +103 -0
  124. package/bundled-skills/seo-plan/SKILL.md +136 -0
  125. package/bundled-skills/seo-plan/assets/agency.md +175 -0
  126. package/bundled-skills/seo-plan/assets/ecommerce.md +167 -0
  127. package/bundled-skills/seo-plan/assets/generic.md +144 -0
  128. package/bundled-skills/seo-plan/assets/local-service.md +160 -0
  129. package/bundled-skills/seo-plan/assets/publisher.md +153 -0
  130. package/bundled-skills/seo-plan/assets/saas.md +135 -0
  131. package/bundled-skills/seo-programmatic/SKILL.md +184 -0
  132. package/bundled-skills/seo-schema/SKILL.md +178 -0
  133. package/bundled-skills/seo-sitemap/SKILL.md +129 -0
  134. package/bundled-skills/seo-technical/SKILL.md +175 -0
  135. package/bundled-skills/site-architecture/SKILL.md +366 -0
  136. package/bundled-skills/site-architecture/evals/evals.json +88 -0
  137. package/bundled-skills/site-architecture/references/mermaid-templates.md +216 -0
  138. package/bundled-skills/site-architecture/references/navigation-patterns.md +305 -0
  139. package/bundled-skills/site-architecture/references/site-type-templates.md +293 -0
  140. package/bundled-skills/skill-improver/SKILL.md +1 -1
  141. package/bundled-skills/tavily-web/SKILL.md +1 -1
  142. package/bundled-skills/test-fixing/SKILL.md +1 -1
  143. package/bundled-skills/tool-design/SKILL.md +1 -1
  144. package/bundled-skills/ui-ux-pro-max/SKILL.md +1 -1
  145. package/bundled-skills/verification-before-completion/SKILL.md +1 -1
  146. package/bundled-skills/wiki-changelog/SKILL.md +1 -1
  147. package/bundled-skills/wiki-onboarding/SKILL.md +1 -1
  148. package/bundled-skills/wiki-qa/SKILL.md +1 -1
  149. package/bundled-skills/wiki-researcher/SKILL.md +1 -1
  150. package/bundled-skills/wiki-vitepress/SKILL.md +1 -1
  151. package/package.json +1 -1
@@ -0,0 +1,587 @@
1
+ # Tool Use — Python
2
+
3
+ For conceptual overview (tool definitions, tool choice, tips), see [shared/tool-use-concepts.md](../../shared/tool-use-concepts.md).
4
+
5
+ ## Tool Runner (Recommended)
6
+
7
+ **Beta:** The tool runner is in beta in the Python SDK.
8
+
9
+ Use the `@beta_tool` decorator to define tools as typed functions, then pass them to `client.beta.messages.tool_runner()`:
10
+
11
+ ```python
12
+ import anthropic
13
+ from anthropic import beta_tool
14
+
15
+ client = anthropic.Anthropic()
16
+
17
+ @beta_tool
18
+ def get_weather(location: str, unit: str = "celsius") -> str:
19
+ """Get current weather for a location.
20
+
21
+ Args:
22
+ location: City and state, e.g., San Francisco, CA.
23
+ unit: Temperature unit, either "celsius" or "fahrenheit".
24
+ """
25
+ # Your implementation here
26
+ return f"72°F and sunny in {location}"
27
+
28
+ # The tool runner handles the agentic loop automatically
29
+ runner = client.beta.messages.tool_runner(
30
+ model="claude-opus-4-6",
31
+ max_tokens=4096,
32
+ tools=[get_weather],
33
+ messages=[{"role": "user", "content": "What's the weather in Paris?"}],
34
+ )
35
+
36
+ # Each iteration yields a BetaMessage; iteration stops when Claude is done
37
+ for message in runner:
38
+ print(message)
39
+ ```
40
+
41
+ For async usage, use `@beta_async_tool` with `async def` functions.
42
+
43
+ **Key benefits of the tool runner:**
44
+
45
+ - No manual loop — the SDK handles calling tools and feeding results back
46
+ - Type-safe tool inputs via decorators
47
+ - Tool schemas are generated automatically from function signatures
48
+ - Iteration stops automatically when Claude has no more tool calls
49
+
50
+ ---
51
+
52
+ ## MCP Tool Conversion Helpers
53
+
54
+ **Beta.** Convert [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) tools, prompts, and resources to Anthropic API types for use with the tool runner. Requires `pip install anthropic[mcp]` (Python 3.10+).
55
+
56
+ > **Note:** The Claude API also supports an `mcp_servers` parameter that lets Claude connect directly to remote MCP servers. Use these helpers instead when you need local MCP servers, prompts, resources, or more control over the MCP connection.
57
+
58
+ ### MCP Tools with Tool Runner
59
+
60
+ ```python
61
+ from anthropic import AsyncAnthropic
62
+ from anthropic.lib.tools.mcp import async_mcp_tool
63
+ from mcp import ClientSession
64
+ from mcp.client.stdio import stdio_client, StdioServerParameters
65
+
66
+ client = AsyncAnthropic()
67
+
68
+ async with stdio_client(StdioServerParameters(command="mcp-server")) as (read, write):
69
+ async with ClientSession(read, write) as mcp_client:
70
+ await mcp_client.initialize()
71
+
72
+ tools_result = await mcp_client.list_tools()
73
+ runner = await client.beta.messages.tool_runner(
74
+ model="claude-opus-4-6",
75
+ max_tokens=1024,
76
+ messages=[{"role": "user", "content": "Use the available tools"}],
77
+ tools=[async_mcp_tool(t, mcp_client) for t in tools_result.tools],
78
+ )
79
+ async for message in runner:
80
+ print(message)
81
+ ```
82
+
83
+ For sync usage, use `mcp_tool` instead of `async_mcp_tool`.
84
+
85
+ ### MCP Prompts
86
+
87
+ ```python
88
+ from anthropic.lib.tools.mcp import mcp_message
89
+
90
+ prompt = await mcp_client.get_prompt(name="my-prompt")
91
+ response = await client.beta.messages.create(
92
+ model="claude-opus-4-6",
93
+ max_tokens=1024,
94
+ messages=[mcp_message(m) for m in prompt.messages],
95
+ )
96
+ ```
97
+
98
+ ### MCP Resources as Content
99
+
100
+ ```python
101
+ from anthropic.lib.tools.mcp import mcp_resource_to_content
102
+
103
+ resource = await mcp_client.read_resource(uri="file:///path/to/doc.txt")
104
+ response = await client.beta.messages.create(
105
+ model="claude-opus-4-6",
106
+ max_tokens=1024,
107
+ messages=[{
108
+ "role": "user",
109
+ "content": [
110
+ mcp_resource_to_content(resource),
111
+ {"type": "text", "text": "Summarize this document"},
112
+ ],
113
+ }],
114
+ )
115
+ ```
116
+
117
+ ### Upload MCP Resources as Files
118
+
119
+ ```python
120
+ from anthropic.lib.tools.mcp import mcp_resource_to_file
121
+
122
+ resource = await mcp_client.read_resource(uri="file:///path/to/data.json")
123
+ uploaded = await client.beta.files.upload(file=mcp_resource_to_file(resource))
124
+ ```
125
+
126
+ Conversion functions raise `UnsupportedMCPValueError` if an MCP value cannot be converted (e.g., unsupported content types like audio, unsupported MIME types).
127
+
128
+ ---
129
+
130
+ ## Manual Agentic Loop
131
+
132
+ Use this when you need fine-grained control over the loop (e.g., custom logging, conditional tool execution, human-in-the-loop approval):
133
+
134
+ ```python
135
+ import anthropic
136
+
137
+ client = anthropic.Anthropic()
138
+ tools = [...] # Your tool definitions
139
+ messages = [{"role": "user", "content": user_input}]
140
+
141
+ # Agentic loop: keep going until Claude stops calling tools
142
+ while True:
143
+ response = client.messages.create(
144
+ model="claude-opus-4-6",
145
+ max_tokens=4096,
146
+ tools=tools,
147
+ messages=messages
148
+ )
149
+
150
+ # If Claude is done (no more tool calls), break
151
+ if response.stop_reason == "end_turn":
152
+ break
153
+
154
+ # Server-side tool hit iteration limit; re-send to continue
155
+ if response.stop_reason == "pause_turn":
156
+ messages = [
157
+ {"role": "user", "content": user_input},
158
+ {"role": "assistant", "content": response.content},
159
+ ]
160
+ continue
161
+
162
+ # Extract tool use blocks from the response
163
+ tool_use_blocks = [b for b in response.content if b.type == "tool_use"]
164
+
165
+ # Append assistant's response (including tool_use blocks)
166
+ messages.append({"role": "assistant", "content": response.content})
167
+
168
+ # Execute each tool and collect results
169
+ tool_results = []
170
+ for tool in tool_use_blocks:
171
+ result = execute_tool(tool.name, tool.input) # Your implementation
172
+ tool_results.append({
173
+ "type": "tool_result",
174
+ "tool_use_id": tool.id, # Must match the tool_use block's id
175
+ "content": result
176
+ })
177
+
178
+ # Append tool results as a user message
179
+ messages.append({"role": "user", "content": tool_results})
180
+
181
+ # Final response text
182
+ final_text = next(b.text for b in response.content if b.type == "text")
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Handling Tool Results
188
+
189
+ ```python
190
+ response = client.messages.create(
191
+ model="claude-opus-4-6",
192
+ max_tokens=1024,
193
+ tools=tools,
194
+ messages=[{"role": "user", "content": "What's the weather in Paris?"}]
195
+ )
196
+
197
+ for block in response.content:
198
+ if block.type == "tool_use":
199
+ tool_name = block.name
200
+ tool_input = block.input
201
+ tool_use_id = block.id
202
+
203
+ result = execute_tool(tool_name, tool_input)
204
+
205
+ followup = client.messages.create(
206
+ model="claude-opus-4-6",
207
+ max_tokens=1024,
208
+ tools=tools,
209
+ messages=[
210
+ {"role": "user", "content": "What's the weather in Paris?"},
211
+ {"role": "assistant", "content": response.content},
212
+ {
213
+ "role": "user",
214
+ "content": [{
215
+ "type": "tool_result",
216
+ "tool_use_id": tool_use_id,
217
+ "content": result
218
+ }]
219
+ }
220
+ ]
221
+ )
222
+ ```
223
+
224
+ ---
225
+
226
+ ## Multiple Tool Calls
227
+
228
+ ```python
229
+ tool_results = []
230
+
231
+ for block in response.content:
232
+ if block.type == "tool_use":
233
+ result = execute_tool(block.name, block.input)
234
+ tool_results.append({
235
+ "type": "tool_result",
236
+ "tool_use_id": block.id,
237
+ "content": result
238
+ })
239
+
240
+ # Send all results back at once
241
+ if tool_results:
242
+ followup = client.messages.create(
243
+ model="claude-opus-4-6",
244
+ max_tokens=1024,
245
+ tools=tools,
246
+ messages=[
247
+ *previous_messages,
248
+ {"role": "assistant", "content": response.content},
249
+ {"role": "user", "content": tool_results}
250
+ ]
251
+ )
252
+ ```
253
+
254
+ ---
255
+
256
+ ## Error Handling in Tool Results
257
+
258
+ ```python
259
+ tool_result = {
260
+ "type": "tool_result",
261
+ "tool_use_id": tool_use_id,
262
+ "content": "Error: Location 'xyz' not found. Please provide a valid city name.",
263
+ "is_error": True
264
+ }
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Tool Choice
270
+
271
+ ```python
272
+ response = client.messages.create(
273
+ model="claude-opus-4-6",
274
+ max_tokens=1024,
275
+ tools=tools,
276
+ tool_choice={"type": "tool", "name": "get_weather"}, # Force specific tool
277
+ messages=[{"role": "user", "content": "What's the weather in Paris?"}]
278
+ )
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Code Execution
284
+
285
+ ### Basic Usage
286
+
287
+ ```python
288
+ import anthropic
289
+
290
+ client = anthropic.Anthropic()
291
+
292
+ response = client.messages.create(
293
+ model="claude-opus-4-6",
294
+ max_tokens=4096,
295
+ messages=[{
296
+ "role": "user",
297
+ "content": "Calculate the mean and standard deviation of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
298
+ }],
299
+ tools=[{
300
+ "type": "code_execution_20260120",
301
+ "name": "code_execution"
302
+ }]
303
+ )
304
+
305
+ for block in response.content:
306
+ if block.type == "text":
307
+ print(block.text)
308
+ elif block.type == "bash_code_execution_tool_result":
309
+ print(f"stdout: {block.content.stdout}")
310
+ ```
311
+
312
+ ### Upload Files for Analysis
313
+
314
+ ```python
315
+ # 1. Upload a file
316
+ uploaded = client.beta.files.upload(file=open("sales_data.csv", "rb"))
317
+
318
+ # 2. Pass to code execution via container_upload block
319
+ # Code execution is GA; Files API is still beta (pass via extra_headers)
320
+ response = client.messages.create(
321
+ model="claude-opus-4-6",
322
+ max_tokens=4096,
323
+ extra_headers={"anthropic-beta": "files-api-2025-04-14"},
324
+ messages=[{
325
+ "role": "user",
326
+ "content": [
327
+ {"type": "text", "text": "Analyze this sales data. Show trends and create a visualization."},
328
+ {"type": "container_upload", "file_id": uploaded.id}
329
+ ]
330
+ }],
331
+ tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
332
+ )
333
+ ```
334
+
335
+ ### Retrieve Generated Files
336
+
337
+ ```python
338
+ import os
339
+
340
+ OUTPUT_DIR = "./claude_outputs"
341
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
342
+
343
+ for block in response.content:
344
+ if block.type == "bash_code_execution_tool_result":
345
+ result = block.content
346
+ if result.type == "bash_code_execution_result" and result.content:
347
+ for file_ref in result.content:
348
+ if file_ref.type == "bash_code_execution_output":
349
+ metadata = client.beta.files.retrieve_metadata(file_ref.file_id)
350
+ file_content = client.beta.files.download(file_ref.file_id)
351
+ # Use basename to prevent path traversal; validate result
352
+ safe_name = os.path.basename(metadata.filename)
353
+ if not safe_name or safe_name in (".", ".."):
354
+ print(f"Skipping invalid filename: {metadata.filename}")
355
+ continue
356
+ output_path = os.path.join(OUTPUT_DIR, safe_name)
357
+ file_content.write_to_file(output_path)
358
+ print(f"Saved: {output_path}")
359
+ ```
360
+
361
+ ### Container Reuse
362
+
363
+ ```python
364
+ # First request: set up environment
365
+ response1 = client.messages.create(
366
+ model="claude-opus-4-6",
367
+ max_tokens=4096,
368
+ messages=[{"role": "user", "content": "Install tabulate and create data.json with sample data"}],
369
+ tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
370
+ )
371
+
372
+ # Get container ID from response
373
+ container_id = response1.container.id
374
+
375
+ # Second request: reuse the same container
376
+ response2 = client.messages.create(
377
+ container=container_id,
378
+ model="claude-opus-4-6",
379
+ max_tokens=4096,
380
+ messages=[{"role": "user", "content": "Read data.json and display as a formatted table"}],
381
+ tools=[{"type": "code_execution_20260120", "name": "code_execution"}]
382
+ )
383
+ ```
384
+
385
+ ### Response Structure
386
+
387
+ ```python
388
+ for block in response.content:
389
+ if block.type == "text":
390
+ print(block.text) # Claude's explanation
391
+ elif block.type == "server_tool_use":
392
+ print(f"Running: {block.name} - {block.input}") # What Claude is doing
393
+ elif block.type == "bash_code_execution_tool_result":
394
+ result = block.content
395
+ if result.type == "bash_code_execution_result":
396
+ if result.return_code == 0:
397
+ print(f"Output: {result.stdout}")
398
+ else:
399
+ print(f"Error: {result.stderr}")
400
+ else:
401
+ print(f"Tool error: {result.error_code}")
402
+ elif block.type == "text_editor_code_execution_tool_result":
403
+ print(f"File operation: {block.content}")
404
+ ```
405
+
406
+ ---
407
+
408
+ ## Memory Tool
409
+
410
+ ### Basic Usage
411
+
412
+ ```python
413
+ import anthropic
414
+
415
+ client = anthropic.Anthropic()
416
+
417
+ response = client.messages.create(
418
+ model="claude-opus-4-6",
419
+ max_tokens=2048,
420
+ messages=[{"role": "user", "content": "Remember that my preferred language is Python."}],
421
+ tools=[{"type": "memory_20250818", "name": "memory"}],
422
+ )
423
+ ```
424
+
425
+ ### SDK Memory Helper
426
+
427
+ Subclass `BetaAbstractMemoryTool`:
428
+
429
+ ```python
430
+ from anthropic.lib.tools import BetaAbstractMemoryTool
431
+
432
+ class MyMemoryTool(BetaAbstractMemoryTool):
433
+ def view(self, command): ...
434
+ def create(self, command): ...
435
+ def str_replace(self, command): ...
436
+ def insert(self, command): ...
437
+ def delete(self, command): ...
438
+ def rename(self, command): ...
439
+
440
+ memory = MyMemoryTool()
441
+
442
+ # Use with tool runner
443
+ runner = client.beta.messages.tool_runner(
444
+ model="claude-opus-4-6",
445
+ max_tokens=2048,
446
+ tools=[memory],
447
+ messages=[{"role": "user", "content": "Remember my preferences"}],
448
+ )
449
+
450
+ for message in runner:
451
+ print(message)
452
+ ```
453
+
454
+ For full implementation examples, use WebFetch:
455
+
456
+ - `https://github.com/anthropics/anthropic-sdk-python/blob/main/examples/memory/basic.py`
457
+
458
+ ---
459
+
460
+ ## Structured Outputs
461
+
462
+ ### JSON Outputs (Pydantic — Recommended)
463
+
464
+ ```python
465
+ from pydantic import BaseModel
466
+ from typing import List
467
+ import anthropic
468
+
469
+ class ContactInfo(BaseModel):
470
+ name: str
471
+ email: str
472
+ plan: str
473
+ interests: List[str]
474
+ demo_requested: bool
475
+
476
+ client = anthropic.Anthropic()
477
+
478
+ response = client.messages.parse(
479
+ model="claude-opus-4-6",
480
+ max_tokens=1024,
481
+ messages=[{
482
+ "role": "user",
483
+ "content": "Extract: Jane Doe (jane@co.com) wants Enterprise, interested in API and SDKs, wants a demo."
484
+ }],
485
+ output_format=ContactInfo,
486
+ )
487
+
488
+ # response.parsed_output is a validated ContactInfo instance
489
+ contact = response.parsed_output
490
+ print(contact.name) # "Jane Doe"
491
+ print(contact.interests) # ["API", "SDKs"]
492
+ ```
493
+
494
+ ### Raw Schema
495
+
496
+ ```python
497
+ response = client.messages.create(
498
+ model="claude-opus-4-6",
499
+ max_tokens=1024,
500
+ messages=[{
501
+ "role": "user",
502
+ "content": "Extract info: John Smith (john@example.com) wants the Enterprise plan."
503
+ }],
504
+ output_config={
505
+ "format": {
506
+ "type": "json_schema",
507
+ "schema": {
508
+ "type": "object",
509
+ "properties": {
510
+ "name": {"type": "string"},
511
+ "email": {"type": "string"},
512
+ "plan": {"type": "string"},
513
+ "demo_requested": {"type": "boolean"}
514
+ },
515
+ "required": ["name", "email", "plan", "demo_requested"],
516
+ "additionalProperties": False
517
+ }
518
+ }
519
+ }
520
+ )
521
+
522
+ import json
523
+ data = json.loads(response.content[0].text)
524
+ ```
525
+
526
+ ### Strict Tool Use
527
+
528
+ ```python
529
+ response = client.messages.create(
530
+ model="claude-opus-4-6",
531
+ max_tokens=1024,
532
+ messages=[{"role": "user", "content": "Book a flight to Tokyo for 2 passengers on March 15"}],
533
+ tools=[{
534
+ "name": "book_flight",
535
+ "description": "Book a flight to a destination",
536
+ "strict": True,
537
+ "input_schema": {
538
+ "type": "object",
539
+ "properties": {
540
+ "destination": {"type": "string"},
541
+ "date": {"type": "string", "format": "date"},
542
+ "passengers": {"type": "integer", "enum": [1, 2, 3, 4, 5, 6, 7, 8]}
543
+ },
544
+ "required": ["destination", "date", "passengers"],
545
+ "additionalProperties": False
546
+ }
547
+ }]
548
+ )
549
+ ```
550
+
551
+ ### Using Both Together
552
+
553
+ ```python
554
+ response = client.messages.create(
555
+ model="claude-opus-4-6",
556
+ max_tokens=1024,
557
+ messages=[{"role": "user", "content": "Plan a trip to Paris next month"}],
558
+ output_config={
559
+ "format": {
560
+ "type": "json_schema",
561
+ "schema": {
562
+ "type": "object",
563
+ "properties": {
564
+ "summary": {"type": "string"},
565
+ "next_steps": {"type": "array", "items": {"type": "string"}}
566
+ },
567
+ "required": ["summary", "next_steps"],
568
+ "additionalProperties": False
569
+ }
570
+ }
571
+ },
572
+ tools=[{
573
+ "name": "search_flights",
574
+ "description": "Search for available flights",
575
+ "strict": True,
576
+ "input_schema": {
577
+ "type": "object",
578
+ "properties": {
579
+ "destination": {"type": "string"},
580
+ "date": {"type": "string", "format": "date"}
581
+ },
582
+ "required": ["destination", "date"],
583
+ "additionalProperties": False
584
+ }
585
+ }]
586
+ )
587
+ ```
@@ -0,0 +1,87 @@
1
+ # Claude API — Ruby
2
+
3
+ > **Note:** The Ruby SDK supports the Claude API. A tool runner is available in beta via `client.beta.messages.tool_runner()`. Agent SDK is not yet available for Ruby.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install anthropic
9
+ ```
10
+
11
+ ## Client Initialization
12
+
13
+ ```ruby
14
+ require "anthropic"
15
+
16
+ # Default (uses ANTHROPIC_API_KEY env var)
17
+ client = Anthropic::Client.new
18
+
19
+ # Explicit API key
20
+ client = Anthropic::Client.new(api_key: "your-api-key")
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Basic Message Request
26
+
27
+ ```ruby
28
+ message = client.messages.create(
29
+ model: :"claude-opus-4-6",
30
+ max_tokens: 1024,
31
+ messages: [
32
+ { role: "user", content: "What is the capital of France?" }
33
+ ]
34
+ )
35
+ puts message.content.first.text
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Streaming
41
+
42
+ ```ruby
43
+ stream = client.messages.stream(
44
+ model: :"claude-opus-4-6",
45
+ max_tokens: 1024,
46
+ messages: [{ role: "user", content: "Write a haiku" }]
47
+ )
48
+
49
+ stream.text.each { |text| print(text) }
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Tool Use
55
+
56
+ The Ruby SDK supports tool use via raw JSON schema definitions and also provides a beta tool runner for automatic tool execution.
57
+
58
+ ### Tool Runner (Beta)
59
+
60
+ ```ruby
61
+ class GetWeatherInput < Anthropic::BaseModel
62
+ required :location, String, doc: "City and state, e.g. San Francisco, CA"
63
+ end
64
+
65
+ class GetWeather < Anthropic::BaseTool
66
+ doc "Get the current weather for a location"
67
+
68
+ input_schema GetWeatherInput
69
+
70
+ def call(input)
71
+ "The weather in #{input.location} is sunny and 72°F."
72
+ end
73
+ end
74
+
75
+ client.beta.messages.tool_runner(
76
+ model: :"claude-opus-4-6",
77
+ max_tokens: 1024,
78
+ tools: [GetWeather.new],
79
+ messages: [{ role: "user", content: "What's the weather in San Francisco?" }]
80
+ ).each_message do |message|
81
+ puts message.content
82
+ end
83
+ ```
84
+
85
+ ### Manual Loop
86
+
87
+ See the [shared tool use concepts](../shared/tool-use-concepts.md) for the tool definition format and agentic loop pattern.