-
Notifications
You must be signed in to change notification settings - Fork 17
feat: context caching #377
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
Closed
Closed
Changes from 30 commits
Commits
Show all changes
154 commits
Select commit
Hold shift + click to select a range
fd010d0
feat: Add enhanced environment validation with fallbacks
Adebesin-Cell 60326ef
fix: merge conflicts
Adebesin-Cell 1c97dd6
style: Improve error handling and logging efficiency
Adebesin-Cell bfefd8c
refactor: Improve error handling and messages in AgentLoader
Adebesin-Cell 2f88506
refactor: Remove redundant environment validation code
Adebesin-Cell 6537f47
docs: Remove ENVIRONMENT_VARIABLES.md file
Adebesin-Cell 4e7e9e9
feat: Add environment variable validation with clear error messages
Adebesin-Cell 65a0493
refactor: Improve error handling in agent loading
Adebesin-Cell 98b4abe
Merge branch 'main' of https://github.com/IQAIcom/adk-ts into fix/env…
Adebesin-Cell 15af11b
Merge branch 'main' of https://github.com/IQAIcom/adk-ts into fix/env…
Adebesin-Cell c0016b6
feat: Add agent resolver with cache cleanup utilities
Adebesin-Cell 6cddbb7
refactor: Improve error handling in AgentLoader
Adebesin-Cell df8392b
style: Remove unnecessary import statement
Adebesin-Cell acba09e
fix: merge conflicts
Adebesin-Cell 0731091
feat: Add global exception filter for pretty error formatting
Adebesin-Cell 099c473
fix: merge conflicts
Adebesin-Cell ad2544b
fix: multiple cache file creation
Adebesin-Cell 74223fc
fix: error handling in adk-cli
Adebesin-Cell d874b7c
Merge branch 'main' into fix/env-error
Royal-lobster f8584a7
fix: merge conflicts
Adebesin-Cell bbc2c75
feat: Add ContextCacheConfig class for context caching
Adebesin-Cell 103e6a2
docs: Remove unnecessary adk.code-workspace file
Adebesin-Cell b4908a5
Merge branch 'feat/add-tracing' of https://github.com/IQAIcom/adk-ts …
Adebesin-Cell 582547a
Merge branch 'feat/add-tracing' of https://github.com/IQAIcom/adk-ts …
Adebesin-Cell cef481a
feat: Add context caching for Gemini models
Adebesin-Cell 877ae0f
refactor: Improve cache handling in GeminiContextCacheManager
Adebesin-Cell 0185839
refactor: Simplify cache contents slicing logic
Adebesin-Cell e2de24a
Update packages/adk/src/agents/invocation-context.ts
Adebesin-Cell 0263fc7
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell adad054
fix: Add error handling for missing model name
Adebesin-Cell 8217ec7
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell 6d35321
style: Remove unnecessary commented code
Adebesin-Cell 4de123d
style: Improve code readability with type annotations
Adebesin-Cell b043645
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell 37897bc
refactor: Improve data canonicalization in GeminiContextCacheManager
Adebesin-Cell d300fb9
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell f930d2a
style: Update variable names and hash length slicing functionality
Adebesin-Cell 12aae2a
refactor: Update GeminiContextCacheManager constructor arguments
Adebesin-Cell 0492b66
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell 8a1554c
feat: Add method to configure context caching in AgentBuilder
Adebesin-Cell 3998fe0
feat: Add context caching feature for Gemini models
Adebesin-Cell 2d5b4bd
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell 82a923a
feat: Update context caching model version to 2.5
Adebesin-Cell 31e9fa9
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell f89c1d2
Merge branch 'feat/add-tracing' of https://github.com/IQAIcom/adk-ts …
Adebesin-Cell a686c24
refactor: Remove redundant contextCacheConfig assignment
Adebesin-Cell 8a32059
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell 853b83f
chore: Add constants and deprecate in-memory service
Adebesin-Cell 5e08160
refactor: Update cache management logic for Gemini context
Adebesin-Cell 04fc17f
feat: Add tools to createCacheConfig if available
Adebesin-Cell b18fd5c
Update packages/adk/src/runners.ts
Adebesin-Cell 7383543
feat: Add method to extract cache metadata from session history
Adebesin-Cell 98bdda2
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell 7131b37
refactor: Refactor models structure for clarity
Adebesin-Cell 262842b
feat: Add UsageMetadata import and typecasting
Adebesin-Cell cc8d291
Update packages/adk/src/models/gemini-context-cache-manager.ts
Adebesin-Cell 51f0db9
docs: Update context caching configuration settings
Adebesin-Cell a22d4b3
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell c8316b4
refactor: Remove unused constant variables in GeminiContextCacheManager
Adebesin-Cell ecf5d69
Merge branch 'feat/add-tracing' into feat/support-caching
Adebesin-Cell fe10adc
feat: Add context caching for Google models
Adebesin-Cell 459ef07
chore(models): Update import order in ai-sdk file
Adebesin-Cell e5aeacc
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell dc6b51e
refactor: Remove unused code related to cache management
Adebesin-Cell f4120f9
fix: Fix typo in context cache intervals value
Adebesin-Cell 5e1c54e
Merge branch 'feat/add-tracing' into feat/support-caching
Adebesin-Cell 0eb6ffc
Refine documentation for model integration options and improve clarit…
Timonwa f64b61b
Merge branch 'feat/add-tracing' of https://github.com/IQAIcom/adk-ts …
Adebesin-Cell d7fc031
style: Improve context caching documentation message
Adebesin-Cell 0bb3f9e
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell 9bf55d0
Enhance documentation on artifact deletion and cleanup strategies. Ad…
Pelumi-Aderinto 40de7ea
Refactor artifact cleanup service documentation. Updated the `Artifac…
Pelumi-Aderinto 36aa62b
Refactor `ArtifactCleanupService` documentation. Updated import state…
Pelumi-Aderinto 80baccd
Refactor artifact cleanup functionality. Simplified the `cleanupTempo…
Pelumi-Aderinto 95a1edd
docs: fixed errors in code snippets and rearranged the functions
Timonwa 64c8919
docs: update workflow agents documentation for clarity and consistency
Timonwa 193a464
docs: update session links to point to the correct session documentation
Timonwa a131c82
Update artifact cleanup documentation. Renamed section to "Artifact C…
Pelumi-Aderinto 8aef807
Enhance artifact cleanup documentation. Renamed section to "Artifact …
Pelumi-Aderinto e56583a
Add listing versions section to artifact documentation. Introduced th…
Pelumi-Aderinto 4459cbc
fix: conflicts
Adebesin-Cell 5e2ab7a
docs: enhance workflow and sequential agents documentation with clear…
Timonwa 6cc723c
docs: remove outdated quick start example for workflow agents
Timonwa 2945e29
docs: update sequential agents example for clarity and structure
Timonwa b6c5bdf
docs: refine sequential agents example for clarity and consistency
Timonwa d3f6ace
docs: update parallel agents example for clarity and detail
Timonwa c5ac16d
docs: forgot to update quick start examples intro for parallel and se…
Timonwa ec929ef
docs: update quick start example for research synthesis agent with im…
Timonwa 185e20b
docs: enhance code comments for clarity in LangGraph and Loop agents …
Timonwa 0b0ac77
docs: enhance customer support workflow example with detailed agent d…
Timonwa c8925ef
docs: refine custom agents documentation for clarity and detail, enha…
Timonwa bef43f0
docs: enhance multi-agent systems documentation with detailed agent d…
Timonwa abf89c0
docs: load environment variables from .env file in agent builder and …
Timonwa e29ca30
docs: enhance LLM agents documentation with improved clarity, structu…
Timonwa bb9699c
docs: refine LangGraph agents documentation with improved examples an…
Timonwa e703484
Merge remote-tracking branch 'origin/main' into check-agents-section-…
Timonwa 6dd948a
Merge branch 'feat/add-tracing' into feat/support-caching
Adebesin-Cell 47ab1a4
refactor: Simplify message fetching logic and attachments handling
Adebesin-Cell 9b5fde2
setup
MarvelNwachukwu 7aa07a2
docs: update agent builder examples to include dotenv configuration a…
Timonwa 39f9de6
docs: update llm-agents documentation to correct appName type from Ba…
Timonwa 2953826
docs: update dotenv import syntax and configuration usage in agent ex…
Timonwa e828944
docs: fix typo in import statement for LoopAgent in multi-agents example
Timonwa d08c933
Update apps/adk-web/hooks/use-agent.ts
Adebesin-Cell 9f1cf2f
refactor: Simplify message transformation and add type guards
Adebesin-Cell 95dc71a
style: Simplify mapping function parameters in use-agent hook
Adebesin-Cell c340b7c
Merge branch 'main' of https://github.com/IQAIcom/adk-ts into fix/env…
Adebesin-Cell a11e821
refactor: Simplify code by removing unnecessary type annotations
Adebesin-Cell fc8e655
Merge pull request #391 from IQAIcom/fix/env-error
Adebesin-Cell 18b8a64
feat: Add step to install dependencies
Adebesin-Cell 94d05b7
Merge branch 'main' into fix/agent-context
Adebesin-Cell 515c53a
Merge pull request #393 from IQAIcom/check-agents-section-code-snippets
Timonwa d952803
Merge branch 'main' into fix/agent-context
Adebesin-Cell 4b9f016
Merge pull request #394 from IQAIcom/fix/agent-context
Adebesin-Cell 173b8cf
Version Packages
github-actions[bot] 1de9180
Merge pull request #396 from IQAIcom/changeset-release/main
Adebesin-Cell 7d03483
feat: Add typescript dependency
Adebesin-Cell 9b39d9c
style: remove unused code in package.json and client.ts
Adebesin-Cell 51546dd
fix: Update version of @modelcontextprotocol/sdk to 1.11.1
Adebesin-Cell 3aca356
feat: Add prompts capability
Adebesin-Cell d7acef6
fix: Update @modelcontextprotocol/sdk to version 1.17.5
Adebesin-Cell 6c3b921
fix: remove invalid params
Adebesin-Cell 8d5f928
refactor: Remove unused properties in McpClientService
Adebesin-Cell cec1eaa
Merge pull request #389 from IQAIcom/feature/artifact-docs
Pelumi-Aderinto a98adac
fix: mcp type errors
Adebesin-Cell c642258
fix: add lock
Adebesin-Cell b938be4
fix: resolve type errors with Model Context Protocol versioning
Adebesin-Cell d8049ec
Update packages/adk/src/tools/mcp/sampling-handler.ts
Adebesin-Cell 80614a4
refactor: Improve handling of mcpContent data types
Adebesin-Cell 3afe3d9
Merge branch 'fix/release' of https://github.com/IQAIcom/adk-ts into …
Adebesin-Cell 40b3e7a
refactor: Improve data validation and logging in MCP content conversion
Adebesin-Cell d1c1e19
top three projects image
MarvelNwachukwu 99b42ae
update navbar, showing docs and showcase
MarvelNwachukwu 4cf5063
feat: add community project showcase with dedicated project cards and…
MarvelNwachukwu fc78eed
fix project card hydration error and add project submission instructi…
MarvelNwachukwu e83927e
changed layout
MarvelNwachukwu 837928c
showcase discussion
MarvelNwachukwu f97191c
renamed section and deleted some projects
MarvelNwachukwu 44fda9d
no referrer
MarvelNwachukwu 71e37fb
refactor: extract project data from `page.tsx` into a new `_schema.ts…
MarvelNwachukwu d1ef3eb
add labels
MarvelNwachukwu 21ace7b
lazy loading
MarvelNwachukwu 4c9c5a9
refactor: Update project data schema to use title, description, and t…
MarvelNwachukwu 7809647
Merge pull request #403 from IQAIcom/adk-showcase
MarvelNwachukwu 45645aa
Merge branch 'main' into fix/release
Adebesin-Cell c97621a
Merge pull request #402 from IQAIcom/fix/release
Adebesin-Cell f118046
Version Packages
github-actions[bot] f4fea2d
Merge pull request #405 from IQAIcom/changeset-release/main
Adebesin-Cell 6a3f485
chore: sync ADK versions across examples and starters
actions-user 8c1bef2
fix: merge conflicts
Adebesin-Cell 1af6dad
Merge branch 'feat/support-caching' of https://github.com/IQAIcom/adk…
Adebesin-Cell d7d0528
refactor: Improve caching logic for AI SDK
Adebesin-Cell 1e38a2a
chore: update
Adebesin-Cell 111206b
refactor: Improve code readability with type assertions
Adebesin-Cell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
apps/docs/content/docs/framework/context/context-caching.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| --- | ||
| title: Context caching with Gemini | ||
| description: This document explains how to configure and use the context caching feature. | ||
| --- | ||
|
|
||
| When working with agents to complete tasks, you may want to reuse extended instructions or large sets of data across multiple agent requests to a generative AI model. Resending this data for each agent request is slow, inefficient, and can be expensive. Using context caching features in generative AI models can significantly speed up responses and lower the number of tokens sent to the model for each request. | ||
|
|
||
| The ADK Context Caching feature allows you to cache request data with generative AI models that support it, including Gemini 2.0 and higher models. This document explains how to configure and use this feature. | ||
|
|
||
|
|
||
| ## Configure context caching | ||
|
|
||
| You configure the context caching feature when creating your agent by passing a `contextCacheConfig` object directly to your agent. For example: | ||
|
|
||
| ```typescript | ||
| const agent = new LlmAgent({ | ||
| model: "gemini-2.5-flash", // Configure an agent using a model that supports context caching | ||
Adebesin-Cell marked this conversation as resolved.
Show resolved
Hide resolved
Adebesin-Cell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ... other agent properties | ||
| contextCacheConfig: { | ||
| cacheIntervals: 10, | ||
| ttlSeconds: 1800, | ||
| minTokens: 1000, | ||
| }, | ||
| }); | ||
| ``` | ||
Adebesin-Cell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Configuration settings | ||
|
|
||
| The `contextCacheConfig` object has the following settings that control how caching works for your agent: | ||
Timonwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| * **minTokens** (`number`): The minimum number of tokens required in a request to enable caching. This avoids caching very small requests where the performance benefit is negligible. **Default:** `0`. | ||
|
|
||
| * **ttlSeconds** (`number`): The time-to-live (TTL) for the cache in seconds. Determines how long cached content is stored before it is refreshed. **Default:** `1800` (30 minutes). | ||
|
|
||
| * **cacheIntervals** (`number`): The maximum number of times the same cached content can be used before it expires. Allows control over how frequently the cache is updated, even if the TTL has not expired. **Default:** `10`. | ||
Adebesin-Cell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * Zod schema defining validation rules for ContextCacheConfig. | ||
| */ | ||
| export const contextCacheConfigSchema = z.object({ | ||
| /** | ||
| * Maximum number of invocations to reuse the same cache before refreshing it. | ||
| * Must be between 1 and 100. | ||
| * | ||
| * @default 10 | ||
| */ | ||
| cacheIntervals: z | ||
| .number() | ||
| .int() | ||
| .min(1, { message: "cacheIntervals must be at least 1." }) | ||
| .max(100, { message: "cacheIntervals must not exceed 100." }) | ||
| .default(10), | ||
|
|
||
| /** | ||
| * Time-to-live for cache in seconds. Must be greater than 0. | ||
| * Default: 1800 (30 minutes). | ||
| * | ||
| * @default 1800 | ||
| */ | ||
| ttlSeconds: z | ||
| .number() | ||
| .int() | ||
| .positive({ message: "ttlSeconds must be greater than 0." }) | ||
| .default(1800), | ||
|
|
||
| /** | ||
| * Minimum estimated request tokens required to enable caching. | ||
| * Set higher to avoid caching small requests where overhead may exceed benefits. | ||
| * | ||
| * @default 0 | ||
| */ | ||
| minTokens: z | ||
| .number() | ||
| .int() | ||
| .min(0, { message: "minTokens must be non-negative." }) | ||
| .default(0), | ||
| }); | ||
|
|
||
| /** | ||
| * Inferred TypeScript type for ContextCacheConfig properties. | ||
| */ | ||
| export type ContextCacheConfigProps = z.infer<typeof contextCacheConfigSchema>; | ||
|
|
||
| /** | ||
| * Configuration for context caching across all agents in an app. | ||
| * | ||
| * This configuration enables and controls context caching behavior for | ||
| * all LLM agents in an app. When this config is present on an app, context | ||
| * caching is enabled for all agents. When absent (null), context caching | ||
| * is disabled. | ||
| * | ||
| * Context caching can significantly reduce costs and improve response times | ||
| * by reusing previously processed context across multiple requests. | ||
| */ | ||
| export class ContextCacheConfig implements ContextCacheConfigProps { | ||
| /** Maximum number of invocations to reuse the same cache before refreshing it. */ | ||
| public cacheIntervals: number; | ||
|
|
||
| /** Time-to-live for cache in seconds. */ | ||
| public ttlSeconds: number; | ||
|
|
||
| /** Minimum estimated request tokens required to enable caching. */ | ||
| public minTokens: number; | ||
|
|
||
| /** | ||
| * Creates a new validated ContextCacheConfig instance. | ||
| * | ||
| */ | ||
| constructor(params: Partial<ContextCacheConfigProps> = {}) { | ||
| const validated = contextCacheConfigSchema.parse(params); | ||
| this.cacheIntervals = validated.cacheIntervals; | ||
| this.ttlSeconds = validated.ttlSeconds; | ||
| this.minTokens = validated.minTokens; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the TTL as a formatted string (e.g., "1800s"). | ||
| * | ||
| */ | ||
| get ttlString(): string { | ||
| return `${this.ttlSeconds}s`; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a readable string representation of the configuration, | ||
| * useful for debugging or logging. | ||
| */ | ||
| toString(): string { | ||
| return `ContextCacheConfig(cache_intervals=${this.cacheIntervals}, ttl=${this.ttlSeconds}s, min_tokens=${this.minTokens})`; | ||
| } | ||
|
|
||
| /** | ||
| * Validates a plain object and returns a new `ContextCacheConfig` instance. | ||
| * | ||
| */ | ||
| static from(data: unknown): ContextCacheConfig { | ||
| const validated = contextCacheConfigSchema.parse(data); | ||
| return new ContextCacheConfig(validated); | ||
| } | ||
|
|
||
| /** | ||
| * Converts the configuration to a plain JavaScript object. | ||
| * | ||
| */ | ||
| toJSON(): ContextCacheConfigProps { | ||
| return { | ||
| cacheIntervals: this.cacheIntervals, | ||
| ttlSeconds: this.ttlSeconds, | ||
| minTokens: this.minTokens, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| export * from "./agent-builder"; | ||
| export * from "./base-agent"; | ||
| export * from "./callback-context"; | ||
| export * from "./context-cache-config"; | ||
| export * from "./invocation-context"; | ||
| export * from "./lang-graph-agent"; | ||
| export * from "./llm-agent"; | ||
| export * from "./sequential-agent"; | ||
| export * from "./parallel-agent"; | ||
| export * from "./loop-agent"; | ||
| export * from "./lang-graph-agent"; | ||
| export * from "./agent-builder"; | ||
| export * from "./run-config"; | ||
| export * from "./invocation-context"; | ||
| export * from "./parallel-agent"; | ||
| export * from "./readonly-context"; | ||
| export * from "./callback-context"; | ||
| export * from "./run-config"; | ||
| export * from "./sequential-agent"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.