Skip to content

Conversation

@keykbd
Copy link
Contributor

@keykbd keykbd commented Nov 6, 2025

Description of Changes

Problem

AgentCore failed with ValidationException when using non-Claude models (e.g., Nova models). Only Claude models were working properly due to hardcoded prompt caching configuration.

Error example:

Error: An error occurred while processing your request: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following errors: Malformed input request: #/toolConfig/tools/18: extraneous key [cachePoint] is not permitted, please reformat your input and try again.

Root Cause

The config.py had hardcoded cache configuration that enabled cache_prompt and cache_tools for all models, but Nova models only support cache_prompt (not cache_tools).

Solution

  • Load model-specific cache configuration from SUPPORTED_CACHE_FIELDS environment variable
  • CDK passes cache configuration based on model capabilities defined in packages/common/model.ts
  • Python runtime conditionally initializes BedrockModel with appropriate cache settings:
    • Claude models: cache_prompt=True, cache_tools=True
    • Nova models: cache_prompt=True (no cache_tools)
    • Other models: No caching (safe default)

Checklist

  • Modified relevant documentation (N/A - code change only)
  • Verified operation in local environment
  • Executed npm run cdk:test and updated snapshots with npm run cdk:test:update-snapshot

Load SUPPORTED_CACHE_FIELDS from environment variable to maintain
single source of truth in TypeScript (packages/common/model.ts).

This follows the same pattern as MCP_SERVERS configuration:
- CDK injects SUPPORTED_CACHE_FIELDS via environment variable
- Python runtime reads from environment
- Claude models: cache_prompt + cache_tools enabled
- Nova models: cache_prompt only (no cache_tools)
- Other models: no caching (safe default)

Changes:
- generic-agent-core.ts: Pass SUPPORTED_CACHE_FIELDS as env var
- config.py: Load from env var with standard Python style
- agent.py: Conditional BedrockModel initialization

Fixes: ValidationException when using Nova models with AgentCore
@tbrand tbrand requested a review from maekawataiki November 11, 2025 01:49
Copy link
Collaborator

@maekawataiki maekawataiki left a comment

Choose a reason for hiding this comment

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

LGTM

@maekawataiki maekawataiki merged commit 8298e9f into aws-samples:main Nov 11, 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.

2 participants