Skip to content

Conversation

@subtleGradient
Copy link
Member

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
Member Author

subtleGradient commented Nov 11, 2025

@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.41001009198100
Added@​effect/​platform@​0.93.310010010098100

View full report

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
@subtleGradient subtleGradient force-pushed the 04-prompt-caching-effect branch from e069c8d to 25cbe98 Compare November 12, 2025 23:18
@subtleGradient subtleGradient force-pushed the 03-prompt-caching-aisdk branch from 6a73a21 to 0147fbe Compare November 12, 2025 23:18
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

@subtleGradient subtleGradient force-pushed the 04-prompt-caching-effect branch from 25cbe98 to ec6d0fd Compare November 19, 2025 11:13
@subtleGradient subtleGradient force-pushed the 03-prompt-caching-aisdk branch from 0147fbe to bfdfeeb Compare November 19, 2025 11:13
Copy link
Member Author

subtleGradient commented Nov 19, 2025

Merge activity

@subtleGradient subtleGradient changed the base branch from 03-prompt-caching-aisdk to graphite-base/44 November 19, 2025 17:42
@subtleGradient subtleGradient changed the base branch from graphite-base/44 to main November 19, 2025 17:43
- 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
@subtleGradient subtleGradient force-pushed the 04-prompt-caching-effect branch from ec6d0fd to a168119 Compare November 19, 2025 17:44
@subtleGradient subtleGradient merged commit 3c8c04b into main Nov 19, 2025
3 checks passed
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