hive-skills 0.1.0
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.
- package/LICENSE +28 -0
- package/README.md +235 -0
- package/assets/LICENSE +32 -0
- package/assets/THIRD_PARTY_NOTICES.md +72 -0
- package/assets/manifest.json +1290 -0
- package/assets/skills/authored/code-review/composable/BUNDLE.md +192 -0
- package/assets/skills/authored/code-review/composable/INDEX.md +13 -0
- package/assets/skills/authored/code-review/composable/VERSION +1 -0
- package/assets/skills/authored/code-review/composable/mini/01-review-method.md +34 -0
- package/assets/skills/authored/code-review/composable/mini/02-security-review.md +20 -0
- package/assets/skills/authored/code-review/composable/mini/03-correctness-bugs.md +19 -0
- package/assets/skills/authored/code-review/composable/mini/04-concurrency.md +16 -0
- package/assets/skills/authored/code-review/composable/mini/05-error-handling.md +12 -0
- package/assets/skills/authored/code-review/composable/mini/06-performance.md +11 -0
- package/assets/skills/authored/code-review/composable/mini/07-api-design.md +20 -0
- package/assets/skills/authored/code-review/composable/mini/08-missing-tests.md +25 -0
- package/assets/skills/authored/code-review/composable/mini/09-refactoring-and-communication.md +32 -0
- package/assets/skills/authored/data-analysis/composable/BUNDLE.md +186 -0
- package/assets/skills/authored/data-analysis/composable/INDEX.md +13 -0
- package/assets/skills/authored/data-analysis/composable/VERSION +1 -0
- package/assets/skills/authored/data-analysis/composable/mini/01-data-quality-profiling.md +26 -0
- package/assets/skills/authored/data-analysis/composable/mini/02-aggregation-pitfalls.md +21 -0
- package/assets/skills/authored/data-analysis/composable/mini/03-time-series.md +19 -0
- package/assets/skills/authored/data-analysis/composable/mini/04-segmentation.md +23 -0
- package/assets/skills/authored/data-analysis/composable/mini/05-discount-pricing.md +17 -0
- package/assets/skills/authored/data-analysis/composable/mini/06-insight-generation.md +25 -0
- package/assets/skills/authored/data-analysis/composable/mini/07-executive-writing.md +26 -0
- package/assets/skills/authored/data-analysis/composable/mini/08-recommendations.md +20 -0
- package/assets/skills/authored/data-analysis/composable/mini/09-reproducibility-assumptions.md +20 -0
- package/assets/skills/authored/financial-analysis/composable/BUNDLE.md +1293 -0
- package/assets/skills/authored/financial-analysis/composable/INDEX.md +17 -0
- package/assets/skills/authored/financial-analysis/composable/VERSION +1 -0
- package/assets/skills/authored/financial-analysis/composable/mini/00-core.md +69 -0
- package/assets/skills/authored/financial-analysis/composable/mini/01-profitability-efficiency-ratios.md +173 -0
- package/assets/skills/authored/financial-analysis/composable/mini/02-liquidity-leverage-ratios.md +120 -0
- package/assets/skills/authored/financial-analysis/composable/mini/03-valuation-ratios-interpretation.md +107 -0
- package/assets/skills/authored/financial-analysis/composable/mini/04-dcf-projection-wacc.md +122 -0
- package/assets/skills/authored/financial-analysis/composable/mini/05-dcf-terminal-value-sensitivity.md +75 -0
- package/assets/skills/authored/financial-analysis/composable/mini/06-comparables-precedents.md +78 -0
- package/assets/skills/authored/financial-analysis/composable/mini/07-budget-variance-analysis.md +47 -0
- package/assets/skills/authored/financial-analysis/composable/mini/08-driver-based-forecasting-scenarios.md +111 -0
- package/assets/skills/authored/financial-analysis/composable/mini/09-rolling-forecasts-accuracy.md +114 -0
- package/assets/skills/authored/financial-analysis/composable/mini/10-reporting-exec-summary.md +58 -0
- package/assets/skills/authored/financial-analysis/composable/mini/11-industry-adaptations.md +130 -0
- package/assets/skills/authored/financial-analysis/composable/mini/12-toolkit-scripts-io.md +102 -0
- package/assets/skills/authored/python-api/composable/BUNDLE.md +389 -0
- package/assets/skills/authored/python-api/composable/INDEX.md +13 -0
- package/assets/skills/authored/python-api/composable/VERSION +1 -0
- package/assets/skills/authored/python-api/composable/mini/01-project-structure.md +44 -0
- package/assets/skills/authored/python-api/composable/mini/02-routing-and-app.md +38 -0
- package/assets/skills/authored/python-api/composable/mini/03-pydantic-models.md +45 -0
- package/assets/skills/authored/python-api/composable/mini/04-validation-and-errors.md +59 -0
- package/assets/skills/authored/python-api/composable/mini/05-dependencies-and-auth.md +60 -0
- package/assets/skills/authored/python-api/composable/mini/06-pagination-filtering.md +44 -0
- package/assets/skills/authored/python-api/composable/mini/07-async-performance.md +30 -0
- package/assets/skills/authored/python-api/composable/mini/08-testing.md +45 -0
- package/assets/skills/authored/python-api/composable/mini/09-middleware-observability.md +29 -0
- package/assets/skills/authored/tech-writing/composable/BUNDLE.md +220 -0
- package/assets/skills/authored/tech-writing/composable/INDEX.md +12 -0
- package/assets/skills/authored/tech-writing/composable/VERSION +1 -0
- package/assets/skills/authored/tech-writing/composable/mini/01-audience-analysis.md +26 -0
- package/assets/skills/authored/tech-writing/composable/mini/02-document-types.md +27 -0
- package/assets/skills/authored/tech-writing/composable/mini/03-readme-quickstart-changelog.md +22 -0
- package/assets/skills/authored/tech-writing/composable/mini/04-information-architecture.md +21 -0
- package/assets/skills/authored/tech-writing/composable/mini/05-style-clarity.md +29 -0
- package/assets/skills/authored/tech-writing/composable/mini/06-breaking-changes-migrations.md +33 -0
- package/assets/skills/authored/tech-writing/composable/mini/07-troubleshooting-security.md +30 -0
- package/assets/skills/authored/tech-writing/composable/mini/08-faq-voice-tone.md +32 -0
- package/assets/skills/converted/claude-api/composable/BUNDLE.md +14996 -0
- package/assets/skills/converted/claude-api/composable/INDEX.md +98 -0
- package/assets/skills/converted/claude-api/composable/VERSION +1 -0
- package/assets/skills/converted/claude-api/composable/mini/00-core.md +235 -0
- package/assets/skills/converted/claude-api/composable/mini/01-model-api-quick-reference.md +258 -0
- package/assets/skills/converted/claude-api/composable/mini/02-common-pitfalls.md +42 -0
- package/assets/skills/converted/claude-api/composable/mini/10-models.md +135 -0
- package/assets/skills/converted/claude-api/composable/mini/11-platform-availability.md +96 -0
- package/assets/skills/converted/claude-api/composable/mini/12-claude-platform-on-aws.md +59 -0
- package/assets/skills/converted/claude-api/composable/mini/13-live-sources.md +143 -0
- package/assets/skills/converted/claude-api/composable/mini/14-error-codes.md +256 -0
- package/assets/skills/converted/claude-api/composable/mini/15-prompt-caching.md +223 -0
- package/assets/skills/converted/claude-api/composable/mini/16-token-counting.md +56 -0
- package/assets/skills/converted/claude-api/composable/mini/17-tool-use-concepts.md +444 -0
- package/assets/skills/converted/claude-api/composable/mini/18-agent-design.md +101 -0
- package/assets/skills/converted/claude-api/composable/mini/19-anthropic-cli.md +246 -0
- package/assets/skills/converted/claude-api/composable/mini/20-model-migration.md +1301 -0
- package/assets/skills/converted/claude-api/composable/mini/30-managed-agents-overview.md +71 -0
- package/assets/skills/converted/claude-api/composable/mini/31-managed-agents-core.md +278 -0
- package/assets/skills/converted/claude-api/composable/mini/32-managed-agents-environments.md +219 -0
- package/assets/skills/converted/claude-api/composable/mini/33-managed-agents-tools.md +366 -0
- package/assets/skills/converted/claude-api/composable/mini/34-managed-agents-events.md +252 -0
- package/assets/skills/converted/claude-api/composable/mini/35-managed-agents-outcomes.md +106 -0
- package/assets/skills/converted/claude-api/composable/mini/36-managed-agents-multiagent.md +101 -0
- package/assets/skills/converted/claude-api/composable/mini/37-managed-agents-webhooks.md +123 -0
- package/assets/skills/converted/claude-api/composable/mini/38-managed-agents-memory.md +197 -0
- package/assets/skills/converted/claude-api/composable/mini/39-managed-agents-scheduled-deployments.md +146 -0
- package/assets/skills/converted/claude-api/composable/mini/40-managed-agents-client-patterns.md +211 -0
- package/assets/skills/converted/claude-api/composable/mini/41-managed-agents-onboarding.md +82 -0
- package/assets/skills/converted/claude-api/composable/mini/42-managed-agents-api-reference.md +441 -0
- package/assets/skills/converted/claude-api/composable/mini/43-managed-agents-self-hosted-sandboxes.md +174 -0
- package/assets/skills/converted/claude-api/composable/mini/50-python-readme.md +564 -0
- package/assets/skills/converted/claude-api/composable/mini/51-python-tool-use.md +590 -0
- package/assets/skills/converted/claude-api/composable/mini/52-python-streaming-batches-files.md +549 -0
- package/assets/skills/converted/claude-api/composable/mini/53-python-managed-agents.md +335 -0
- package/assets/skills/converted/claude-api/composable/mini/55-typescript-readme.md +404 -0
- package/assets/skills/converted/claude-api/composable/mini/56-typescript-tool-use.md +548 -0
- package/assets/skills/converted/claude-api/composable/mini/57-typescript-streaming-batches-files.md +384 -0
- package/assets/skills/converted/claude-api/composable/mini/58-typescript-managed-agents.md +358 -0
- package/assets/skills/converted/claude-api/composable/mini/60-csharp-readme.md +361 -0
- package/assets/skills/converted/claude-api/composable/mini/61-csharp-tool-use.md +163 -0
- package/assets/skills/converted/claude-api/composable/mini/62-csharp-streaming-batches-files.md +64 -0
- package/assets/skills/converted/claude-api/composable/mini/65-go-readme.md +185 -0
- package/assets/skills/converted/claude-api/composable/mini/66-go-tool-use.md +219 -0
- package/assets/skills/converted/claude-api/composable/mini/67-go-streaming-files.md +63 -0
- package/assets/skills/converted/claude-api/composable/mini/68-go-managed-agents.md +564 -0
- package/assets/skills/converted/claude-api/composable/mini/70-java-readme.md +237 -0
- package/assets/skills/converted/claude-api/composable/mini/71-java-tool-use.md +227 -0
- package/assets/skills/converted/claude-api/composable/mini/72-java-streaming-files.md +49 -0
- package/assets/skills/converted/claude-api/composable/mini/73-java-managed-agents.md +443 -0
- package/assets/skills/converted/claude-api/composable/mini/75-php-readme.md +173 -0
- package/assets/skills/converted/claude-api/composable/mini/76-php-tool-use.md +252 -0
- package/assets/skills/converted/claude-api/composable/mini/77-php-streaming-batches-files.md +53 -0
- package/assets/skills/converted/claude-api/composable/mini/78-php-managed-agents.md +443 -0
- package/assets/skills/converted/claude-api/composable/mini/80-ruby-readme.md +133 -0
- package/assets/skills/converted/claude-api/composable/mini/81-ruby-tool-use-streaming.md +56 -0
- package/assets/skills/converted/claude-api/composable/mini/82-ruby-managed-agents.md +394 -0
- package/assets/skills/converted/claude-api/composable/mini/85-curl-examples.md +255 -0
- package/assets/skills/converted/claude-api/composable/mini/86-curl-managed-agents.md +340 -0
- package/assets/skills/converted/claude-api/composable/presets/csharp.md +1151 -0
- package/assets/skills/converted/claude-api/composable/presets/curl.md +1154 -0
- package/assets/skills/converted/claude-api/composable/presets/go.md +1598 -0
- package/assets/skills/converted/claude-api/composable/presets/java.md +1523 -0
- package/assets/skills/converted/claude-api/composable/presets/php.md +1488 -0
- package/assets/skills/converted/claude-api/composable/presets/python.md +2605 -0
- package/assets/skills/converted/claude-api/composable/presets/ruby.md +1146 -0
- package/assets/skills/converted/claude-api/composable/presets/shared.md +6478 -0
- package/assets/skills/converted/claude-api/composable/presets/typescript.md +2261 -0
- package/assets/skills/converted/docx/composable/BUNDLE.md +617 -0
- package/assets/skills/converted/docx/composable/INDEX.md +12 -0
- package/assets/skills/converted/docx/composable/VERSION +1 -0
- package/assets/skills/converted/docx/composable/mini/00-core.md +26 -0
- package/assets/skills/converted/docx/composable/mini/01-reading-converting.md +36 -0
- package/assets/skills/converted/docx/composable/mini/02-creating-setup-layout.md +85 -0
- package/assets/skills/converted/docx/composable/mini/03-creating-elements.md +257 -0
- package/assets/skills/converted/docx/composable/mini/04-editing-existing.md +57 -0
- package/assets/skills/converted/docx/composable/mini/05-xml-reference.md +128 -0
- package/assets/skills/converted/internal-comms/composable/BUNDLE.md +220 -0
- package/assets/skills/converted/internal-comms/composable/INDEX.md +11 -0
- package/assets/skills/converted/internal-comms/composable/VERSION +1 -0
- package/assets/skills/converted/internal-comms/composable/mini/00-core.md +30 -0
- package/assets/skills/converted/internal-comms/composable/mini/01-3p-updates.md +49 -0
- package/assets/skills/converted/internal-comms/composable/mini/02-company-newsletter.md +67 -0
- package/assets/skills/converted/internal-comms/composable/mini/03-faq-answers.md +32 -0
- package/assets/skills/converted/internal-comms/composable/mini/04-general-comms.md +18 -0
- package/assets/skills/converted/mcp-builder/composable/BUNDLE.md +2460 -0
- package/assets/skills/converted/mcp-builder/composable/INDEX.md +23 -0
- package/assets/skills/converted/mcp-builder/composable/VERSION +1 -0
- package/assets/skills/converted/mcp-builder/composable/mini/00-core.md +43 -0
- package/assets/skills/converted/mcp-builder/composable/mini/01-workflow-research-planning.md +54 -0
- package/assets/skills/converted/mcp-builder/composable/mini/02-implementation-process.md +78 -0
- package/assets/skills/converted/mcp-builder/composable/mini/03-naming-conventions.md +33 -0
- package/assets/skills/converted/mcp-builder/composable/mini/04-response-formats.md +21 -0
- package/assets/skills/converted/mcp-builder/composable/mini/05-pagination.md +24 -0
- package/assets/skills/converted/mcp-builder/composable/mini/06-transport.md +47 -0
- package/assets/skills/converted/mcp-builder/composable/mini/07-annotations.md +20 -0
- package/assets/skills/converted/mcp-builder/composable/mini/08-security.md +35 -0
- package/assets/skills/converted/mcp-builder/composable/mini/09-error-handling.md +32 -0
- package/assets/skills/converted/mcp-builder/composable/mini/10-testing-and-documentation.md +21 -0
- package/assets/skills/converted/mcp-builder/composable/mini/11-python-implementation.md +432 -0
- package/assets/skills/converted/mcp-builder/composable/mini/12-python-advanced-and-checklist.md +233 -0
- package/assets/skills/converted/mcp-builder/composable/mini/13-node-implementation.md +717 -0
- package/assets/skills/converted/mcp-builder/composable/mini/14-node-advanced-and-checklist.md +200 -0
- package/assets/skills/converted/mcp-builder/composable/mini/15-evaluation-design.md +200 -0
- package/assets/skills/converted/mcp-builder/composable/mini/16-evaluation-running.md +198 -0
- package/assets/skills/converted/mcp-builder/composable/presets/node-server.md +1381 -0
- package/assets/skills/converted/mcp-builder/composable/presets/python-server.md +1129 -0
- package/assets/skills/converted/pdf/composable/BUNDLE.md +1284 -0
- package/assets/skills/converted/pdf/composable/INDEX.md +14 -0
- package/assets/skills/converted/pdf/composable/VERSION +1 -0
- package/assets/skills/converted/pdf/composable/mini/00-core.md +46 -0
- package/assets/skills/converted/pdf/composable/mini/01-creation.md +176 -0
- package/assets/skills/converted/pdf/composable/mini/02-extraction.md +178 -0
- package/assets/skills/converted/pdf/composable/mini/03-merge-split-manipulate.md +240 -0
- package/assets/skills/converted/pdf/composable/mini/04-images-ocr.md +168 -0
- package/assets/skills/converted/pdf/composable/mini/05-encryption.md +51 -0
- package/assets/skills/converted/pdf/composable/mini/06-forms.md +300 -0
- package/assets/skills/converted/pdf/composable/mini/07-libraries-reference.md +89 -0
- package/assets/skills/converted/pptx/composable/BUNDLE.md +911 -0
- package/assets/skills/converted/pptx/composable/INDEX.md +12 -0
- package/assets/skills/converted/pptx/composable/VERSION +1 -0
- package/assets/skills/converted/pptx/composable/mini/00-core.md +37 -0
- package/assets/skills/converted/pptx/composable/mini/01-reading.md +37 -0
- package/assets/skills/converted/pptx/composable/mini/02-creating-from-scratch.md +422 -0
- package/assets/skills/converted/pptx/composable/mini/03-editing-templates.md +207 -0
- package/assets/skills/converted/pptx/composable/mini/04-design.md +89 -0
- package/assets/skills/converted/pptx/composable/mini/05-qa-and-rendering.md +91 -0
- package/assets/skills/converted/pptx/composable/presets/creating.md +659 -0
- package/assets/skills/converted/pptx/composable/presets/editing.md +485 -0
- package/assets/skills/converted/skill-creator/composable/BUNDLE.md +1681 -0
- package/assets/skills/converted/skill-creator/composable/INDEX.md +21 -0
- package/assets/skills/converted/skill-creator/composable/VERSION +1 -0
- package/assets/skills/converted/skill-creator/composable/mini/00-core.md +59 -0
- package/assets/skills/converted/skill-creator/composable/mini/01-creating-a-skill.md +27 -0
- package/assets/skills/converted/skill-creator/composable/mini/02-skill-writing-guide.md +71 -0
- package/assets/skills/converted/skill-creator/composable/mini/03-test-cases.md +21 -0
- package/assets/skills/converted/skill-creator/composable/mini/04-running-and-evaluating.md +128 -0
- package/assets/skills/converted/skill-creator/composable/mini/05-improving-the-skill.md +30 -0
- package/assets/skills/converted/skill-creator/composable/mini/06-blind-comparison.md +5 -0
- package/assets/skills/converted/skill-creator/composable/mini/07-description-optimization.md +74 -0
- package/assets/skills/converted/skill-creator/composable/mini/08-packaging.md +11 -0
- package/assets/skills/converted/skill-creator/composable/mini/09-environment-specific.md +38 -0
- package/assets/skills/converted/skill-creator/composable/mini/10-scripts-and-references.md +34 -0
- package/assets/skills/converted/skill-creator/composable/mini/11-json-schemas.md +414 -0
- package/assets/skills/converted/skill-creator/composable/mini/12-agent-grader.md +225 -0
- package/assets/skills/converted/skill-creator/composable/mini/13-agent-comparator.md +204 -0
- package/assets/skills/converted/skill-creator/composable/mini/14-agent-analyzer.md +276 -0
- package/assets/skills/converted/skill-creator/composable/presets/authoring.md +198 -0
- package/assets/skills/converted/skill-creator/composable/presets/evaluating.md +1334 -0
- package/assets/skills/converted/skill-creator/composable/presets/optimizing.md +160 -0
- package/assets/skills/converted/skill-creator/composable/presets.json +5 -0
- package/assets/skills/meta/ccs-skill-creator/composable/BUNDLE.md +465 -0
- package/assets/skills/meta/ccs-skill-creator/composable/INDEX.md +8 -0
- package/assets/skills/meta/ccs-skill-creator/composable/VERSION +1 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/00-core.md +46 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/01-create-new-skill.md +167 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/02-convert-existing-skill.md +120 -0
- package/assets/skills/meta/ccs-skill-creator/composable/mini/03-review-and-maintain.md +112 -0
- package/assets/skills/sources/anthropic/PROVENANCE.md +3 -0
- package/assets/skills/sources/anthropic/claude-api/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/docx/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/internal-comms/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/mcp-builder/LICENSE.txt +202 -0
- package/assets/skills/sources/anthropic/pdf/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/pptx/LICENSE.txt +30 -0
- package/assets/skills/sources/anthropic/skill-creator/LICENSE.txt +202 -0
- package/assets/skills/sources/financial-analyst/PROVENANCE.md +1 -0
- package/assets/tools/hive.py +728 -0
- package/dist/cli.js +7494 -0
- package/package.json +40 -0
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
# Managed Agents — PHP
|
|
2
|
+
|
|
3
|
+
> **Bindings not shown here:** This README covers the most common managed-agents flows for PHP. If you need a class, method, namespace, field, or behavior that isn't shown, WebFetch the PHP SDK repo **or the relevant docs page** from `shared/live-sources.md` rather than guess. Do not extrapolate from cURL shapes or another language's SDK.
|
|
4
|
+
|
|
5
|
+
> **Agents are persistent — create once, reference by ID.** Store the agent ID returned by `$client->beta->agents->create` and pass it to every subsequent `->sessions->create`; do not call `agents->create` in the request path. The Anthropic CLI is one convenient way to create agents and environments from version-controlled YAML — its URL is in `shared/live-sources.md`. The examples below show in-code creation for completeness; in production the create call belongs in setup, not in the request path.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
composer require "anthropic-ai/sdk" "guzzlehttp/guzzle:^7"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Client Initialization
|
|
14
|
+
|
|
15
|
+
```php
|
|
16
|
+
use Anthropic\Client;
|
|
17
|
+
|
|
18
|
+
// Default (uses ANTHROPIC_API_KEY env var)
|
|
19
|
+
$client = new Client();
|
|
20
|
+
|
|
21
|
+
// Explicit API key
|
|
22
|
+
$client = new Client(apiKey: 'your-api-key');
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Create an Environment
|
|
28
|
+
|
|
29
|
+
```php
|
|
30
|
+
$environment = $client->beta->environments->create(
|
|
31
|
+
name: 'my-dev-env',
|
|
32
|
+
config: ['type' => 'cloud', 'networking' => ['type' => 'unrestricted']],
|
|
33
|
+
);
|
|
34
|
+
echo "Environment ID: {$environment->id}\n"; // env_...
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Create an Agent (required first step)
|
|
40
|
+
|
|
41
|
+
> ⚠️ **There is no inline agent config.** `model`/`system`/`tools` live on the agent object, not the session. Always start with `$client->beta->agents->create()` — the session takes either `agent: $agent->id` or the typed `BetaManagedAgentsAgentParams::with(type: 'agent', id: $agent->id, version: $agent->version)`.
|
|
42
|
+
|
|
43
|
+
### Minimal
|
|
44
|
+
|
|
45
|
+
```php
|
|
46
|
+
use Anthropic\Beta\Agents\BetaManagedAgentsAgentToolset20260401Params;
|
|
47
|
+
|
|
48
|
+
// 1. Create the agent (reusable, versioned)
|
|
49
|
+
$agent = $client->beta->agents->create(
|
|
50
|
+
name: 'Coding Assistant',
|
|
51
|
+
model: 'claude-opus-4-8',
|
|
52
|
+
system: 'You are a helpful coding assistant.',
|
|
53
|
+
tools: [
|
|
54
|
+
BetaManagedAgentsAgentToolset20260401Params::with(
|
|
55
|
+
type: 'agent_toolset_20260401',
|
|
56
|
+
),
|
|
57
|
+
],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// 2. Start a session
|
|
61
|
+
$session = $client->beta->sessions->create(
|
|
62
|
+
agent: ['type' => 'agent', 'id' => $agent->id, 'version' => $agent->version],
|
|
63
|
+
environmentID: $environment->id,
|
|
64
|
+
title: 'Quickstart session',
|
|
65
|
+
);
|
|
66
|
+
echo "Session ID: {$session->id}\n";
|
|
67
|
+
echo "Trace: https://platform.claude.com/workspaces/default/sessions/{$session->id}\n";
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Updating an Agent
|
|
71
|
+
|
|
72
|
+
Updates create new versions; the agent object is immutable per version.
|
|
73
|
+
|
|
74
|
+
```php
|
|
75
|
+
$updatedAgent = $client->beta->agents->update(
|
|
76
|
+
$agent->id,
|
|
77
|
+
version: $agent->version,
|
|
78
|
+
system: 'You are a helpful coding agent. Always write tests.',
|
|
79
|
+
);
|
|
80
|
+
echo "New version: {$updatedAgent->version}\n";
|
|
81
|
+
|
|
82
|
+
// List all versions
|
|
83
|
+
foreach ($client->beta->agents->versions->list($agent->id)->pagingEachItem() as $version) {
|
|
84
|
+
echo "Version {$version->version}: {$version->updatedAt->format(DateTimeInterface::ATOM)}\n";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Archive the agent
|
|
88
|
+
$archived = $client->beta->agents->archive($agent->id);
|
|
89
|
+
echo "Archived at: {$archived->archivedAt->format(DateTimeInterface::ATOM)}\n";
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Send a User Message
|
|
95
|
+
|
|
96
|
+
```php
|
|
97
|
+
$client->beta->sessions->events->send(
|
|
98
|
+
$session->id,
|
|
99
|
+
events: [
|
|
100
|
+
[
|
|
101
|
+
'type' => 'user.message',
|
|
102
|
+
'content' => [['type' => 'text', 'text' => 'Review the auth module']],
|
|
103
|
+
],
|
|
104
|
+
],
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> 💡 **Stream-first:** Open the stream *before* (or concurrently with) sending the message. The stream only delivers events that occur after it opens — stream-after-send means early events arrive buffered in one batch. See [Steering Patterns](../../shared/managed-agents-events.md#steering-patterns).
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Stream Events (SSE)
|
|
113
|
+
|
|
114
|
+
> ℹ️ **Streaming transporter:** PHP's default buffered PSR-18 client never returns for the open-ended session event stream. Use a streaming Guzzle transporter for `streamStream()` calls — other calls keep the default client.
|
|
115
|
+
|
|
116
|
+
```php
|
|
117
|
+
$streamingClient = new GuzzleHttp\Client(['stream' => true]);
|
|
118
|
+
|
|
119
|
+
// Open the stream first, then send the user message
|
|
120
|
+
$stream = $client->beta->sessions->events->streamStream(
|
|
121
|
+
$session->id,
|
|
122
|
+
requestOptions: ['transporter' => $streamingClient],
|
|
123
|
+
);
|
|
124
|
+
$client->beta->sessions->events->send(
|
|
125
|
+
$session->id,
|
|
126
|
+
events: [
|
|
127
|
+
[
|
|
128
|
+
'type' => 'user.message',
|
|
129
|
+
'content' => [['type' => 'text', 'text' => 'Summarize the repo README']],
|
|
130
|
+
],
|
|
131
|
+
],
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
foreach ($stream as $event) {
|
|
135
|
+
match ($event->type) {
|
|
136
|
+
'agent.message' => array_walk(
|
|
137
|
+
$event->content,
|
|
138
|
+
static fn($block) => $block->type === 'text' ? print($block->text) : null,
|
|
139
|
+
),
|
|
140
|
+
'agent.tool_use' => print("\n[Using tool: {$event->name}]\n"),
|
|
141
|
+
'session.error' => printf("\n[Error: %s]", $event->error?->message ?? 'unknown'),
|
|
142
|
+
default => null,
|
|
143
|
+
};
|
|
144
|
+
if ($event->type === 'session.status_idle' || $event->type === 'session.error') {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
$stream->close();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Reconnecting and Tailing
|
|
152
|
+
|
|
153
|
+
When reconnecting mid-session, list past events first to dedupe, then tail live events:
|
|
154
|
+
|
|
155
|
+
```php
|
|
156
|
+
$stream = $client->beta->sessions->events->streamStream(
|
|
157
|
+
$session->id,
|
|
158
|
+
requestOptions: ['transporter' => $streamingClient],
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// Stream is open and buffering. List history before tailing live.
|
|
162
|
+
$seenEventIds = [];
|
|
163
|
+
foreach ($client->beta->sessions->events->list($session->id)->pagingEachItem() as $event) {
|
|
164
|
+
$seenEventIds[$event->id] = true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Tail live events, skipping anything already seen
|
|
168
|
+
foreach ($stream as $event) {
|
|
169
|
+
if (isset($seenEventIds[$event->id])) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
$seenEventIds[$event->id] = true;
|
|
173
|
+
match ($event->type) {
|
|
174
|
+
'agent.message' => array_walk(
|
|
175
|
+
$event->content,
|
|
176
|
+
static fn($block) => $block->type === 'text' ? print($block->text) : null,
|
|
177
|
+
),
|
|
178
|
+
default => null,
|
|
179
|
+
};
|
|
180
|
+
if ($event->type === 'session.status_idle') {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
$stream->close();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Provide Custom Tool Result
|
|
190
|
+
|
|
191
|
+
> ℹ️ The PHP managed-agents bindings for `user.custom_tool_result` are not yet documented in this skill or in the apps source examples. Refer to `shared/managed-agents-events.md` for the wire format and the `anthropic-ai/sdk` PHP repository for the corresponding params.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Poll Events
|
|
196
|
+
|
|
197
|
+
```php
|
|
198
|
+
foreach ($client->beta->sessions->events->list($session->id)->pagingEachItem() as $event) {
|
|
199
|
+
echo "{$event->type}: {$event->id}\n";
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Upload a File
|
|
206
|
+
|
|
207
|
+
> ℹ️ **PHP file upload:** The PHP SDK's beta managed-agents file upload binding is not shown in the apps source examples; the canonical PHP example uses raw cURL against `POST /v1/files`. If your codebase prefers the SDK, WebFetch the `anthropic-ai/sdk` PHP repository for the latest binding before writing code.
|
|
208
|
+
|
|
209
|
+
```php
|
|
210
|
+
use Anthropic\Beta\Sessions\BetaManagedAgentsFileResourceParams;
|
|
211
|
+
|
|
212
|
+
// Raw cURL upload (canonical example from the apps source)
|
|
213
|
+
$csvPath = 'data.csv';
|
|
214
|
+
$ch = curl_init('https://api.anthropic.com/v1/files');
|
|
215
|
+
curl_setopt_array($ch, [
|
|
216
|
+
CURLOPT_RETURNTRANSFER => true,
|
|
217
|
+
CURLOPT_POST => true,
|
|
218
|
+
CURLOPT_HTTPHEADER => [
|
|
219
|
+
'x-api-key: ' . getenv('ANTHROPIC_API_KEY'),
|
|
220
|
+
'anthropic-version: 2023-06-01',
|
|
221
|
+
'anthropic-beta: files-api-2025-04-14',
|
|
222
|
+
],
|
|
223
|
+
CURLOPT_POSTFIELDS => ['file' => new CURLFile($csvPath, 'text/csv', 'data.csv')],
|
|
224
|
+
]);
|
|
225
|
+
$file = json_decode(curl_exec($ch));
|
|
226
|
+
echo "File ID: {$file->id}\n";
|
|
227
|
+
|
|
228
|
+
// Mount in a session
|
|
229
|
+
$session = $client->beta->sessions->create(
|
|
230
|
+
agent: $agent->id,
|
|
231
|
+
environmentID: $environment->id,
|
|
232
|
+
resources: [
|
|
233
|
+
BetaManagedAgentsFileResourceParams::with(
|
|
234
|
+
type: 'file',
|
|
235
|
+
fileID: $file->id,
|
|
236
|
+
mountPath: '/workspace/data.csv',
|
|
237
|
+
),
|
|
238
|
+
],
|
|
239
|
+
);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Add and Manage Resources on an Existing Session
|
|
243
|
+
|
|
244
|
+
```php
|
|
245
|
+
// Attach an additional file to an open session
|
|
246
|
+
$resource = $client->beta->sessions->resources->add(
|
|
247
|
+
$session->id,
|
|
248
|
+
type: 'file',
|
|
249
|
+
fileID: $file->id,
|
|
250
|
+
);
|
|
251
|
+
echo "{$resource->id}\n"; // "sesrsc_01ABC..."
|
|
252
|
+
|
|
253
|
+
// List resources on the session
|
|
254
|
+
$listed = $client->beta->sessions->resources->list($session->id);
|
|
255
|
+
foreach ($listed->data as $entry) {
|
|
256
|
+
echo "{$entry->id} {$entry->type}\n";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Detach a resource
|
|
260
|
+
$client->beta->sessions->resources->delete($resource->id, sessionID: $session->id);
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## List and Download Session Files
|
|
266
|
+
|
|
267
|
+
```php
|
|
268
|
+
$files = $client->beta->files->list(
|
|
269
|
+
scopeID: 'sesn_abc123',
|
|
270
|
+
betas: ['managed-agents-2026-04-01'],
|
|
271
|
+
);
|
|
272
|
+
$content = $client->beta->files->download($files->data[0]->id);
|
|
273
|
+
file_put_contents('output.txt', $content);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Session Management
|
|
279
|
+
|
|
280
|
+
```php
|
|
281
|
+
// List environments
|
|
282
|
+
$environments = $client->beta->environments->list();
|
|
283
|
+
|
|
284
|
+
// Retrieve a specific environment
|
|
285
|
+
$env = $client->beta->environments->retrieve($environment->id);
|
|
286
|
+
|
|
287
|
+
// Archive an environment (read-only, existing sessions continue)
|
|
288
|
+
$client->beta->environments->archive($environment->id);
|
|
289
|
+
|
|
290
|
+
// Delete an environment (only if no sessions reference it)
|
|
291
|
+
$client->beta->environments->delete($environment->id);
|
|
292
|
+
|
|
293
|
+
// Delete a session
|
|
294
|
+
$client->beta->sessions->delete($session->id);
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## MCP Server Integration
|
|
300
|
+
|
|
301
|
+
```php
|
|
302
|
+
use Anthropic\Beta\Agents\BetaManagedAgentsAgentToolset20260401Params;
|
|
303
|
+
use Anthropic\Beta\Agents\BetaManagedAgentsMCPToolsetParams;
|
|
304
|
+
use Anthropic\Beta\Agents\BetaManagedAgentsURLMCPServerParams;
|
|
305
|
+
use Anthropic\Beta\Sessions\BetaManagedAgentsAgentParams;
|
|
306
|
+
|
|
307
|
+
// Agent declares MCP server (no auth here — auth goes in a vault)
|
|
308
|
+
$agent = $client->beta->agents->create(
|
|
309
|
+
name: 'GitHub Assistant',
|
|
310
|
+
model: 'claude-opus-4-8',
|
|
311
|
+
mcpServers: [
|
|
312
|
+
BetaManagedAgentsURLMCPServerParams::with(
|
|
313
|
+
type: 'url',
|
|
314
|
+
name: 'github',
|
|
315
|
+
url: 'https://api.githubcopilot.com/mcp/',
|
|
316
|
+
),
|
|
317
|
+
],
|
|
318
|
+
tools: [
|
|
319
|
+
BetaManagedAgentsAgentToolset20260401Params::with(type: 'agent_toolset_20260401'),
|
|
320
|
+
BetaManagedAgentsMCPToolsetParams::with(
|
|
321
|
+
type: 'mcp_toolset',
|
|
322
|
+
mcpServerName: 'github',
|
|
323
|
+
),
|
|
324
|
+
],
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
// Session attaches vault(s) containing credentials for those MCP server URLs
|
|
328
|
+
$session = $client->beta->sessions->create(
|
|
329
|
+
agent: BetaManagedAgentsAgentParams::with(
|
|
330
|
+
type: 'agent',
|
|
331
|
+
id: $agent->id,
|
|
332
|
+
version: $agent->version,
|
|
333
|
+
),
|
|
334
|
+
environmentID: $environment->id,
|
|
335
|
+
vaultIDs: [$vault->id],
|
|
336
|
+
);
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
See `shared/managed-agents-tools.md` §Vaults for creating vaults and adding credentials.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Vaults
|
|
344
|
+
|
|
345
|
+
```php
|
|
346
|
+
// Create a vault
|
|
347
|
+
$vault = $client->beta->vaults->create(
|
|
348
|
+
displayName: 'Alice',
|
|
349
|
+
metadata: ['external_user_id' => 'usr_abc123'],
|
|
350
|
+
);
|
|
351
|
+
echo $vault->id . "\n"; // "vlt_01ABC..."
|
|
352
|
+
|
|
353
|
+
// Add an OAuth credential
|
|
354
|
+
$credential = $client->beta->vaults->credentials->create(
|
|
355
|
+
vaultID: $vault->id,
|
|
356
|
+
displayName: "Alice's Slack",
|
|
357
|
+
auth: [
|
|
358
|
+
'type' => 'mcp_oauth',
|
|
359
|
+
'mcp_server_url' => 'https://mcp.slack.com/mcp',
|
|
360
|
+
'access_token' => 'xoxp-...',
|
|
361
|
+
'expires_at' => '2026-04-15T00:00:00Z',
|
|
362
|
+
'refresh' => [
|
|
363
|
+
'token_endpoint' => 'https://slack.com/api/oauth.v2.access',
|
|
364
|
+
'client_id' => '1234567890.0987654321',
|
|
365
|
+
'scope' => 'channels:read chat:write',
|
|
366
|
+
'refresh_token' => 'xoxe-1-...',
|
|
367
|
+
'token_endpoint_auth' => [
|
|
368
|
+
'type' => 'client_secret_post',
|
|
369
|
+
'client_secret' => 'abc123...',
|
|
370
|
+
],
|
|
371
|
+
],
|
|
372
|
+
],
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
// Rotate the credential (e.g., after a token refresh)
|
|
376
|
+
$client->beta->vaults->credentials->update(
|
|
377
|
+
$credential->id,
|
|
378
|
+
vaultID: $vault->id,
|
|
379
|
+
auth: [
|
|
380
|
+
'type' => 'mcp_oauth',
|
|
381
|
+
'access_token' => 'xoxp-new-...',
|
|
382
|
+
'expires_at' => '2026-05-15T00:00:00Z',
|
|
383
|
+
'refresh' => ['refresh_token' => 'xoxe-1-new-...'],
|
|
384
|
+
],
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// Archive a vault
|
|
388
|
+
$client->beta->vaults->archive($vault->id);
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## GitHub Repository Integration
|
|
394
|
+
|
|
395
|
+
Mount a GitHub repository as a session resource (a vault holds the GitHub MCP credential):
|
|
396
|
+
|
|
397
|
+
```php
|
|
398
|
+
$session = $client->beta->sessions->create(
|
|
399
|
+
agent: $agent->id,
|
|
400
|
+
environmentID: $environment->id,
|
|
401
|
+
vaultIDs: [$vault->id],
|
|
402
|
+
resources: [
|
|
403
|
+
[
|
|
404
|
+
'type' => 'github_repository',
|
|
405
|
+
'url' => 'https://github.com/org/repo',
|
|
406
|
+
'mount_path' => '/workspace/repo',
|
|
407
|
+
'authorization_token' => 'ghp_your_github_token',
|
|
408
|
+
],
|
|
409
|
+
],
|
|
410
|
+
);
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Multiple repositories on the same session:
|
|
414
|
+
|
|
415
|
+
```php
|
|
416
|
+
$resources = [
|
|
417
|
+
[
|
|
418
|
+
'type' => 'github_repository',
|
|
419
|
+
'url' => 'https://github.com/org/frontend',
|
|
420
|
+
'mount_path' => '/workspace/frontend',
|
|
421
|
+
'authorization_token' => 'ghp_your_github_token',
|
|
422
|
+
],
|
|
423
|
+
[
|
|
424
|
+
'type' => 'github_repository',
|
|
425
|
+
'url' => 'https://github.com/org/backend',
|
|
426
|
+
'mount_path' => '/workspace/backend',
|
|
427
|
+
'authorization_token' => 'ghp_your_github_token',
|
|
428
|
+
],
|
|
429
|
+
];
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Rotating a repository's authorization token:
|
|
433
|
+
|
|
434
|
+
```php
|
|
435
|
+
$listed = $client->beta->sessions->resources->list($session->id);
|
|
436
|
+
$repoResourceId = $listed->data[0]->id;
|
|
437
|
+
|
|
438
|
+
$client->beta->sessions->resources->update(
|
|
439
|
+
$repoResourceId,
|
|
440
|
+
sessionID: $session->id,
|
|
441
|
+
authorizationToken: 'ghp_your_new_github_token',
|
|
442
|
+
);
|
|
443
|
+
```
|
|
@@ -0,0 +1,133 @@
|
|
|
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-8",
|
|
30
|
+
max_tokens: 16000,
|
|
31
|
+
messages: [
|
|
32
|
+
{ role: "user", content: "What is the capital of France?" }
|
|
33
|
+
]
|
|
34
|
+
)
|
|
35
|
+
# content is an array of polymorphic block objects (TextBlock, ThinkingBlock,
|
|
36
|
+
# ToolUseBlock, ...). .type is a Symbol — compare with :text, not "text".
|
|
37
|
+
# .text raises NoMethodError on non-TextBlock entries.
|
|
38
|
+
message.content.each do |block|
|
|
39
|
+
puts block.text if block.type == :text
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Extended Thinking
|
|
46
|
+
|
|
47
|
+
> **Fable 5, Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6:** Use adaptive thinking. `budget_tokens` is removed on Fable 5, Opus 4.8, and 4.7 (400 if sent); deprecated on Opus 4.6 and Sonnet 4.6.
|
|
48
|
+
> **Older models:** Use `thinking: { type: "enabled", budget_tokens: N }` (must be < `max_tokens`, min 1024).
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
message = client.messages.create(
|
|
52
|
+
model: :"claude-opus-4-8",
|
|
53
|
+
max_tokens: 16000,
|
|
54
|
+
thinking: { type: "adaptive" },
|
|
55
|
+
messages: [{ role: "user", content: "Solve: 27 * 453" }]
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
message.content.each do |block|
|
|
59
|
+
case block.type
|
|
60
|
+
when :thinking then puts "Thinking: #{block.thinking}"
|
|
61
|
+
when :text then puts "Response: #{block.text}"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Prompt Caching
|
|
69
|
+
|
|
70
|
+
`system_:` (trailing underscore — avoids shadowing `Kernel#system`) takes an array of text blocks; set `cache_control` on the last block. Plain hashes work via the `OrHash` type alias. For placement patterns and the silent-invalidator audit checklist, see `shared/prompt-caching.md`.
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
message = client.messages.create(
|
|
74
|
+
model: :"claude-opus-4-8",
|
|
75
|
+
max_tokens: 16000,
|
|
76
|
+
system_: [
|
|
77
|
+
{ type: "text", text: long_system_prompt, cache_control: { type: "ephemeral" } }
|
|
78
|
+
],
|
|
79
|
+
messages: [{ role: "user", content: "Summarize the key points" }]
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
For 1-hour TTL: `cache_control: { type: "ephemeral", ttl: "1h" }`. There's also a top-level `cache_control:` on `messages.create` that auto-places on the last cacheable block.
|
|
84
|
+
|
|
85
|
+
Verify hits via `message.usage.cache_creation_input_tokens` / `message.usage.cache_read_input_tokens`.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Stop Details
|
|
90
|
+
|
|
91
|
+
When `stop_reason` is `:refusal`, the response includes structured `stop_details`:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
if message.stop_reason == :refusal && message.stop_details
|
|
95
|
+
puts "Category: #{message.stop_details.category}" # e.g. :cyber, :bio, :reasoning_extraction, :frontier_llm, or nil — see docs for the full set
|
|
96
|
+
puts "Explanation: #{message.stop_details.explanation}"
|
|
97
|
+
end
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Refusal fallbacks (Claude Fable 5) — opt in by default.** Fallbacks are opt-in: without them a refused request simply stops. New `claude-fable-5` code should include the server-side `fallbacks` parameter (beta header `server-side-fallback-2026-06-01`, `fallbacks: [{model: "claude-opus-4-8"}]` on the beta messages call) by default. The exact Ruby binding (and the client-side middleware for providers without server-side support) is not documented here — WebFetch the Ruby SDK repo's `examples/` from `shared/live-sources.md`; full semantics in `shared/model-migration.md` → Migrating to Claude Fable 5 → `refusal` stop reason.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Beta Features
|
|
105
|
+
|
|
106
|
+
`betas:` is only valid on `client.beta.messages.create`, not the non-beta path.
|
|
107
|
+
|
|
108
|
+
### Task budgets
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
response = client.beta.messages.create(
|
|
112
|
+
model: :"claude-opus-4-8",
|
|
113
|
+
max_tokens: 16000,
|
|
114
|
+
output_config: { task_budget: { type: :tokens, total: 64_000 } },
|
|
115
|
+
tools: [...],
|
|
116
|
+
messages: [...],
|
|
117
|
+
betas: ["task-budgets-2026-03-13"]
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Error Type
|
|
124
|
+
|
|
125
|
+
`APIStatusError` exposes a `.type` field for programmatic error classification:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
begin
|
|
129
|
+
client.messages.create(...)
|
|
130
|
+
rescue Anthropic::Errors::APIStatusError => e
|
|
131
|
+
puts e.type # :rate_limit_error, :overloaded_error, etc.
|
|
132
|
+
end
|
|
133
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Tool Use — Ruby
|
|
2
|
+
|
|
3
|
+
For conceptual overview (tool definitions, tool choice, tips), see [shared/tool-use-concepts.md](../../shared/tool-use-concepts.md).
|
|
4
|
+
|
|
5
|
+
## Tool Use
|
|
6
|
+
|
|
7
|
+
The Ruby SDK supports tool use via raw JSON schema definitions and also provides a beta tool runner for automatic tool execution.
|
|
8
|
+
|
|
9
|
+
### Tool Runner (Beta)
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
class GetWeatherInput < Anthropic::BaseModel
|
|
13
|
+
required :location, String, doc: "City and state, e.g. San Francisco, CA"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class GetWeather < Anthropic::BaseTool
|
|
17
|
+
doc "Get the current weather for a location"
|
|
18
|
+
|
|
19
|
+
input_schema GetWeatherInput
|
|
20
|
+
|
|
21
|
+
def call(input)
|
|
22
|
+
"The weather in #{input.location} is sunny and 72°F."
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
client.beta.messages.tool_runner(
|
|
27
|
+
model: :"claude-opus-4-8",
|
|
28
|
+
max_tokens: 16000,
|
|
29
|
+
tools: [GetWeather.new],
|
|
30
|
+
messages: [{ role: "user", content: "What's the weather in San Francisco?" }]
|
|
31
|
+
).each_message do |message|
|
|
32
|
+
puts message.content
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Manual Loop
|
|
37
|
+
|
|
38
|
+
See the [shared tool use concepts](../../shared/tool-use-concepts.md) for the tool definition format and agentic loop pattern.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
# Streaming — Ruby
|
|
43
|
+
|
|
44
|
+
## Streaming
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
stream = client.messages.stream(
|
|
48
|
+
model: :"claude-opus-4-8",
|
|
49
|
+
max_tokens: 64000,
|
|
50
|
+
messages: [{ role: "user", content: "Write a haiku" }]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
stream.text.each { |text| print(text) }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|