-
Notifications
You must be signed in to change notification settings - Fork 43
Add prompt-caching examples for Effect AI #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 03-prompt-caching-aisdk
Are you sure you want to change the base?
Conversation
|
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.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this 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.
typescript/effect-ai/src/prompt-caching/anthropic-no-cache-control.ts
Outdated
Show resolved
Hide resolved
typescript/effect-ai/src/prompt-caching/anthropic-user-message-cache.ts
Outdated
Show resolved
Hide resolved
typescript/effect-ai/src/prompt-caching/anthropic-multi-message-cache.ts
Outdated
Show resolved
Hide resolved
189d80e to
9795a98
Compare
998a95f to
6a73a21
Compare
- 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)
e069c8d to
25cbe98
Compare
6a73a21 to
0147fbe
Compare
| "@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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freeze them deps
| 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?', | ||
| }, | ||
| ], | ||
| }, | ||
| ]); |
There was a problem hiding this comment.
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
louisgv
left a comment
There was a problem hiding this 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

Add prompt-caching examples for Effect AI
Run biome format
Simplify Effect AI prompt-caching README to link to main docs
Rename prompt caching examples with anthropic prefix