Skip to content

feat(effect-ai): AnthropicLanguageModel over /anthropic/v1/messages (phase 4) - #96

Merged
anandpant merged 3 commits into
mainfrom
effect/phase-4
Nov 20, 2026
Merged

anandpant merged 3 commits into
mainfrom
effect/phase-4

Conversation

@anandpant

@anandpant anandpant commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 4 of packages/foundry-effect-ai/docs/PLAN.md: AnthropicLanguageModel over Foundry's /anthropic/v1/messages, with internal/anthropic-messages/ (schema, request, response, stream) and internal/models/anthropic.ts.

  • Every request sends anthropic-version: 2023-06-01; fixtures pin it as a golden header.
  • config takes max_tokens and thinking under their wire names. thinking is sent as given (adaptive, enabled with a budget, or disabled). Thinking blocks keep their signature (redacted ones their data) under foundry-anthropic and replay in order.
  • Structured output: models flagged rejectsForcedToolUse in the model list (Opus 5.5, Sonnet 5.5) send output_config.format. All other models get an injected JSON tool, forced by name when it is the only tool, or any alongside application tools, with parallel tool use disabled. The tool's input becomes the only text. In JSON-tool mode, prose beside any tool call is dropped, so an intermediate application tool turn still works with allowEmpty. With thinking on, the JSON tool is offered with auto, because thinking rejects forced tool use. An application tool whose name collides with the JSON tool fails with ToolConfigurationError.
  • Forced tool choices (required, a named tool, oneOf with required) fail with ToolConfigurationError before sending when thinking is on or the model rejects forced tool use (Opus and Sonnet 5.5).
  • eager_input_streaming is never sent. Stream tool input is collected from input_json_delta and parsed at content_block_stop.
  • Strict tools (Tool.Strict) get the Anthropic codec schema and strict: true. Their input is normalized for Toolkit, and the raw input is kept in metadata so replay sends what the model produced. Tools are non-strict by default, as in the Foundry-tested AI SDK adapter.
  • max_tokens defaults to each catalog model's output limit, or 4096 for a raw target that isn't in the catalog.
  • All system messages go to the top-level system. Foundry's support for system messages mid-conversation is unverified.
  • Failures: an in-band error (SSE or an HTTP 200 body) fails with a typed reason: rate_limit_error → RateLimitError, billing_error → QuotaExhaustedError, invalid_request_error → InvalidRequestError, anything else → InternalProviderError. A stream that ends before message_stop fails with InvalidResponseError, and reading stops at message_stop. A tool call cut off by max_tokens is dropped and the finish reports length, in both modes: the stream holds the last tool call until the next block starts or the stop reason is known.

Matrix

The AnthropicLanguageModel row has no todos: text, stream, json, tools, stream-tools, json-tools, image, reasoning, stream-truncated, stream-error, json-native-claude-sonnet-5.5.

  • Language cells run on claude-haiku-4.5; reasoning cells use thinking: { type: 'enabled', budget_tokens: 1024 }, since Haiku 4.5 predates adaptive thinking. The recorded tools and stream-tools first turns carry signed thinking, and the second request replays it.
  • json-native-claude-sonnet-5.5 runs the shared json program on Sonnet 5.5 with thinking: { type: 'adaptive' }, and checks offline that the request has output_config.format and no tool_choice.
  • stream-truncated cuts the recorded stream after message_delta (stop reason already known), so it must not finish. stream-error replays an in-band overloaded_error.
  • Tree-shaking budget: 21,298 bytes measured, 25,000 set.

Checks

  • pnpm run verify passes.
  • pnpm run test:live:effect: all 9 Anthropic live cells pass. In the full run, OpenAI's reasoning cell failed once because gpt-6-luna returned no reasoning summary, and passed on an isolated rerun. This PR doesn't touch OpenAI code.
  • Fixtures contain no stack host, token or non-model RIDs.
  • Extra live probes, not committed: Haiku 4.5 with budget thinking plus generateObject returns the object through the auto JSON tool. A strict tool with a tuple and an optional field works through Foundry without an anthropic-beta header, and the raw input is kept for replay. Offline probes confirmed the max_tokens cut-off behavior in both modes.

Deferred

  • PDF and plain-text documents, citations, and provider-defined tools (server tools, MCP) aren't supported: no cell needs them and Foundry support is unverified. Non-image files fail with InvalidUserInputError; provider-defined tools fail with InvalidRequestError.
  • output_config.effort and the adaptive thinking display option aren't exposed; they can be added when a cell needs them.
  • No anthropic-beta headers are sent.
  • Out of scope: cache_control markers aren't forwarded, and content prepopulated in message_start is ignored. Both are recorded in PLAN.md.

@anandpant anandpant changed the title feat(effect-ai): AnthropicLanguageModel over /anthropic/v1/messages feat(effect-ai): AnthropicLanguageModel over /anthropic/v1/messages (phase 4) Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07c2a25896

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T02:57:23.649647Z 066b79d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

anandpant commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Nov 20, 2:56 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 20, 2:56 AM UTC: @anandpant merged this pull request with Graphite.

@anandpant
anandpant merged commit ec785fd into main Nov 20, 2026
8 checks passed
@anandpant
anandpant deleted the effect/phase-4 branch November 20, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant