Skip to content

Conversation

@subtleGradient
Copy link
Contributor

Add prompt-caching examples for Effect AI

  • Add typescript/effect-ai/src/prompt-caching/user-message-cache.ts
  • Demonstrates cache_control using options.openrouter.cacheControl in Prompt
  • Shows Effect.gen pattern with Layer-based dependency injection
  • Critical configuration: stream_options.include_usage in model config layer
  • Evidence-based verification via response.usage.cachedInputTokens

Run biome format

Simplify Effect AI prompt-caching README to link to main docs

Rename prompt caching examples with anthropic prefix

Copy link
Contributor Author

subtleGradient commented Nov 11, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@socket-security
Copy link

socket-security bot commented Nov 11, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​effect/​platform-bun@​0.83.0991007598100
Added@​effect/​ai-openrouter@​0.6.0811007694100
Added@​effect/​ai@​0.32.11001007898100
Addedeffect@​3.19.31001009198100
Added@​effect/​platform@​0.93.110010010098100

View full report

@subtleGradient subtleGradient marked this pull request as ready for review November 11, 2025 23:53
Copilot AI review requested due to automatic review settings November 11, 2025 23:53
Copilot finished reviewing on behalf of subtleGradient November 11, 2025 23:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Effect AI prompt-caching examples demonstrating Anthropic's prompt caching feature using @effect/ai and @effect/ai-openrouter. The examples showcase Effect-TS patterns including Effect.gen composition, layer-based dependency injection, and type-safe error handling. However, the PR contains multiple documentation inconsistencies where filename references are missing the "anthropic-" prefix that was added during the renaming process.

Key Changes:

  • Added three Anthropic prompt-caching examples for Effect AI with idiomatic Effect patterns
  • Integrated effect-ai workspace into the monorepo
  • Updated main documentation to include Effect AI examples

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
typescript/package.json Adds effect-ai workspace to monorepo
typescript/effect-ai/tsconfig.json TypeScript configuration for Effect AI workspace with Bun types
typescript/effect-ai/package.json Package configuration with Effect AI dependencies and example scripts (scripts reference incorrect filenames)
typescript/effect-ai/README.md Main workspace README documenting Effect patterns (contains broken link to non-existent file)
typescript/effect-ai/src/prompt-caching/README.md Prompt caching examples documentation (multiple filename references missing "anthropic-" prefix, inaccurate description)
typescript/effect-ai/src/prompt-caching/anthropic-user-message-cache.ts Example demonstrating cache_control on user message content (run command references old filename)
typescript/effect-ai/src/prompt-caching/anthropic-no-cache-control.ts Control scenario validating caching behavior (run command references old filename)
typescript/effect-ai/src/prompt-caching/anthropic-multi-message-cache.ts Multi-turn conversation caching example (run command references old filename)
docs/prompt-caching.md Updated with link to Effect AI examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@subtleGradient subtleGradient changed the base branch from 03-prompt-caching-aisdk to graphite-base/44 November 12, 2025 21:36
@subtleGradient subtleGradient force-pushed the 04-prompt-caching-effect branch from 189d80e to 9795a98 Compare November 12, 2025 22:23
@subtleGradient subtleGradient changed the base branch from graphite-base/44 to 03-prompt-caching-aisdk November 12, 2025 22:23
- Add typescript/effect-ai/src/prompt-caching/user-message-cache.ts
- Demonstrates cache_control using options.openrouter.cacheControl in Prompt
- Shows Effect.gen pattern with Layer-based dependency injection
- Critical configuration: stream_options.include_usage in model config layer
- Evidence-based verification via response.usage.cachedInputTokens
Replace hardcoded filename list with run-examples.ts that auto-discovers all .ts files in src/
Benefits:
- Add new example → automatically included in 'bun examples'
- Rename example → no package.json update needed
- Impossible for package.json to reference non-existent files

Also fixes stale filenames (user-message-cache.ts → anthropic-user-message-cache.ts)
Comment on lines +12 to +16
"@effect/ai": "^0.32.1",
"@effect/ai-openrouter": "^0.6.0",
"@effect/platform": "^0.93.0",
"@effect/platform-bun": "^0.83.0",
"effect": "^3.19.3"
Copy link

Choose a reason for hiding this comment

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

freeze them deps

Comment on lines +36 to +52
const makePrompt = () =>
Prompt.make([
{
role: 'user' as const,
content: [
{
type: 'text' as const,
text: largeContext,
// NO cache_control - this is the control
},
{
type: 'text' as const,
text: 'What are the key principles?',
},
],
},
]);
Copy link

Choose a reason for hiding this comment

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

Would pull this into a separate function

Copy link

@louisgv louisgv left a comment

Choose a reason for hiding this comment

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

read better than I thought -- pre-emptively approved

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.

3 participants