Add prompt-caching examples for Effect AI#44
Conversation
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.
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
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" |
| 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.
Would pull this into a separate function
louisgv
left a comment
There was a problem hiding this comment.
read better than I thought -- pre-emptively approved
25cbe98 to
ec6d0fd
Compare
0147fbe to
bfdfeeb
Compare
Merge activity
|
- 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)
- Replace local docs link with https://openrouter.ai/docs/features/prompt-caching - Remove duplicated Effect AI usage examples and notes - Keep README minimal to avoid content going stale - Code examples are in the actual .ts files
ec6d0fd to
a168119
Compare

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