Skip to content

Comments

add feature: config summarisation, context compression, caching#1198

Closed
Insomniac2904 wants to merge 4 commits intokagent-dev:mainfrom
Insomniac2904:feature/querydoc-summarization
Closed

add feature: config summarisation, context compression, caching#1198
Insomniac2904 wants to merge 4 commits intokagent-dev:mainfrom
Insomniac2904:feature/querydoc-summarization

Conversation

@Insomniac2904
Copy link
Contributor

adds feature for #1173.

example use case:

apiVersion: kagent.dev/v1alpha2
kind: Agent
metadata:
  name: storage-agent
spec:
  declarative:
    context:
      cache:
        enabled: true
        cacheIntervals: 5
        minTokens: 200
        ttlSeconds: 3600

      compression:
        enabled: true
        compactionInterval: 10
        overlapSize: 50
        summarizer:
          type: llm
          model: gpt-4o-mini

      windowCompression:
        enabled: true
        maxLength: 4096

Signed-off-by: insomniac2904 <adarshkumar7478@gmail.com>
@peterj
Copy link
Collaborator

peterj commented Jan 11, 2026

this only adds the configuration options to the resources - are the features actually implemented in the ADK library too?

Signed-off-by: insomniac2904 <adarshkumar7478@gmail.com>
@Insomniac2904 Insomniac2904 requested a review from peterj as a code owner January 14, 2026 17:48
Signed-off-by: Adarsh Kumar <109868197+Insomniac2904@users.noreply.github.com>
@Insomniac2904
Copy link
Contributor Author

this only adds the configuration options to the resources - are the features actually implemented in the ADK library too?

Hey @peterj you were right. I could not find the context config for golang, only for python. I have revert back the original changes and made the changes to types.py and _a2a.py files. Also i am not sure for the imports that needs to me made for windowCompression and thus i have not implemented it as of now. Also could you please point me to the right test file, so that i can check my changes.
Thanks.

@dobesv
Copy link
Contributor

dobesv commented Feb 14, 2026

This seems like a very important feature to have, otherwise long sessions with agents might be impossible (?). Any idea what is needed to move this forward? Can I help in any way?

Signed-off-by: Adarsh Kumar <109868197+Insomniac2904@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 16, 2026 07:50
Copy link
Contributor

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

Exposes ADK context management options (compaction/summarization and caching) through the Agent configuration/CRD to help prevent context window overflows for tool-heavy agents (issue #1173).

Changes:

  • Adds Python config models for context compression/caching and a helper to build ADK config objects.
  • Extends the Python A2A app bootstrap to accept context-related configs for ADK App.
  • Updates Agent CRD schema to include .spec.declarative.context (cache + compression).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
python/packages/kagent-adk/src/kagent/adk/types.py Adds context config types + helper; adds context to AgentConfig.
python/packages/kagent-adk/src/kagent/adk/_a2a.py Adds context_configs plumbing into app construction (currently broken/incomplete).
helm/kagent-crds/templates/kagent.dev_agents.yaml Adds CRD schema for .spec.declarative.context.
go/config/crd/bases/kagent.dev_agents.yaml Adds CRD schema for .spec.declarative.context.
go/api/v1alpha2/zz_generated.deepcopy.go Minor generated import formatting change.
Comments suppressed due to low confidence (1)

python/packages/kagent-adk/src/kagent/adk/_a2a.py:109

  • The App(...) created in create_runner() does not include events_compaction_config / context_cache_config, so context compaction/caching will not be enabled even if context_configs is provided. Pass the configs into this App(...) (or reuse the configured App instance).
        def create_runner() -> Runner:
            root_agent = self.root_agent_factory()
            adk_app = App(name=self.app_name, root_agent=root_agent, plugins=self.plugins)


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

self.agent_card = agent_card
self._lifespan = lifespan
self.plugins = plugins if plugins is not None else []
self.context_configs = context_configs or {"compaction": None, "cache": None}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The default context_configs dict uses keys compaction/cache, but build_adk_context_configs(...) currently produces events_compaction_config/context_cache_config. Standardize the keys across the codepath so callers can pass the output through without needing an ad-hoc remap.

Copilot uses AI. Check for mistakes.
Comment on lines +6199 to +6238
context:
properties:
cache:
properties:
cacheIntervals:
type: integer
enabled:
type: boolean
minTokens:
type: integer
ttlSeconds:
type: integer
required:
- enabled
type: object
compression:
properties:
compactionInterval:
type: integer
enabled:
type: boolean
overlapSize:
type: integer
summarizer:
properties:
model:
description: Model to use for summarization (required
if type is llm)
type: string
type:
default: llm
enum:
- llm
- text
type: string
type: object
required:
- enabled
type: object
type: object
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

This CRD schema adds .spec.declarative.context, but the Go API type DeclarativeAgentSpec (go/api/v1alpha2/agent_types.go) does not define a matching field. With controller-runtime typed clients, this config is likely dropped during decode and never reaches the translator/runtime. Add the field to the Go types and regenerate CRDs to keep schema + controller behavior consistent.

Suggested change
context:
properties:
cache:
properties:
cacheIntervals:
type: integer
enabled:
type: boolean
minTokens:
type: integer
ttlSeconds:
type: integer
required:
- enabled
type: object
compression:
properties:
compactionInterval:
type: integer
enabled:
type: boolean
overlapSize:
type: integer
summarizer:
properties:
model:
description: Model to use for summarization (required
if type is llm)
type: string
type:
default: llm
enum:
- llm
- text
type: string
type: object
required:
- enabled
type: object
type: object

Copilot uses AI. Check for mistakes.
Comment on lines +6199 to +6200
context:
properties:
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

The PR description/example includes windowCompression, but the schema here only adds cache and compression. Either add the missing windowCompression config to the CRD (and implement it) or update the PR description to reflect the supported fields.

Copilot uses AI. Check for mistakes.
Comment on lines +237 to +241
def build_adk_context_configs(ctx: Optional[ContextConfig], default_llm: Any) -> Dict[str, Any]:
configs = {
"events_compaction_config": None,
"context_cache_config": None
}
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

build_adk_context_configs uses Dict in the return type but Dict is not imported in this module. Without from __future__ import annotations, this will raise a NameError at import time. Use dict[str, Any] (Py3.11+) or import Dict from typing.

Copilot uses AI. Check for mistakes.
Comment on lines +248 to +252
if ctx.compression.summarizer and ctx.compression.summarizer.type == "llm":
# Use the provided model for summarization, or fall back to the main agent model
summerizer_model_name = ctx.compression.summarizer.model
summarizer_llm = GeminiLLM(model=summerizer_model_name) if summerizer_model_name else default_llm
summarizer = LlmEventSummarizer(llm=summarizer_llm)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

When a summarizer model override is provided, the code always instantiates GeminiLLM(model=...). This will break for non-Gemini model names (e.g. the PR description’s gpt-4o-mini) and also ignores the main agent model provider. Consider either (1) always using default_llm and disallowing provider changes, or (2) extending ContextSummarizerSettings to include a provider/type and constructing the correct ADK LLM wrapper accordingly.

Copilot uses AI. Check for mistakes.
Comment on lines +98 to +102
adk_app = App(
name=self.app_name,
root_agent=self.root_agent,
plugins=self.plugins,
events_compaction_config=self.context_configs.get("compaction"),
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

build() constructs an App(...) with root_agent=self.root_agent, but KAgentApp never defines self.root_agent. This will raise AttributeError the first time build() is called.

Copilot uses AI. Check for mistakes.
cache_intervals=ctx.cache.cache_intervals or 5,
)

return configs
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

There should be a blank line separation between the end of build_adk_context_configs and the next top-level class Bedrock definition; ruff/pycodestyle typically flags this (E305).

Suggested change
return configs
return configs

Copilot uses AI. Check for mistakes.
Comment on lines +6199 to +6238
context:
properties:
cache:
properties:
cacheIntervals:
type: integer
enabled:
type: boolean
minTokens:
type: integer
ttlSeconds:
type: integer
required:
- enabled
type: object
compression:
properties:
compactionInterval:
type: integer
enabled:
type: boolean
overlapSize:
type: integer
summarizer:
properties:
model:
description: Model to use for summarization (required
if type is llm)
type: string
type:
default: llm
enum:
- llm
- text
type: string
type: object
required:
- enabled
type: object
type: object
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

This CRD schema adds .spec.declarative.context, but the Go API type DeclarativeAgentSpec (go/api/v1alpha2/agent_types.go) does not define a matching field. With controller-runtime typed clients, this config is likely dropped during decode and never reaches the translator/runtime. Add the field to the Go types and regenerate CRDs to keep schema + controller behavior consistent.

Suggested change
context:
properties:
cache:
properties:
cacheIntervals:
type: integer
enabled:
type: boolean
minTokens:
type: integer
ttlSeconds:
type: integer
required:
- enabled
type: object
compression:
properties:
compactionInterval:
type: integer
enabled:
type: boolean
overlapSize:
type: integer
summarizer:
properties:
model:
description: Model to use for summarization (required
if type is llm)
type: string
type:
default: llm
enum:
- llm
- text
type: string
type: object
required:
- enabled
type: object
type: object

Copilot uses AI. Check for mistakes.
Comment on lines +220 to +224
class ContextCompressionSettings(BaseModel):
enabled: bool
compaction_interval: Optional[int] = Field(None, alias="compactionInterval")
overlap_size: Optional[int] = Field(None, alias="overlapSize")
summarizer: Optional[ContextSummarizerSettings] = None
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

PEP 8 / ruff: top-level class definitions should be separated by two blank lines. In this new block, the Context*Settings classes are adjacent without the expected spacing, which will typically trigger E302/E305.

Copilot uses AI. Check for mistakes.
Comment on lines 282 to +283
execute_code: bool | None = None
context: Optional[ContextConfig] = None
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

context is added to AgentConfig, but to_agent() does not use it and there’s no wiring here to pass context settings into the ADK App/Runner. As-is, setting .context in config/CRD won’t change runtime behavior.

Copilot uses AI. Check for mistakes.
@dobesv
Copy link
Contributor

dobesv commented Feb 16, 2026

Sorry for the AI slop here. I need to go over this a bit more in detail before it can be merge ready. I'd appreciate some feedback on the approach, though. If I fix all the issues, would you accept it?

@EItanya
Copy link
Contributor

EItanya commented Feb 16, 2026

Closing this in favor of #1298

@EItanya EItanya closed this Feb 16, 2026
@ronbutbul
Copy link

any updates on that matter?
(compression and caching feature)

can not really work like this currently
im hitting token limit very quickly cause every prompt history is being added to the context

@dobesv
Copy link
Contributor

dobesv commented Feb 22, 2026

Working on this in #1340 now

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.

5 participants