Skip to content

feat: allow AgentCore agent selection in Applications#726

Open
michaelraskansky wants to merge 2 commits intoaws-samples:mainfrom
michaelraskansky:feature/agentcore-applications
Open

feat: allow AgentCore agent selection in Applications#726
michaelraskansky wants to merge 2 commits intoaws-samples:mainfrom
michaelraskansky:feature/agentcore-applications

Conversation

@michaelraskansky
Copy link
Copy Markdown
Contributor

Summary

Adds the ability for admins to configure an Application with an Amazon Bedrock AgentCore agent, optionally alongside a model and model settings. Regular users can then chat with agents through the Application interface.

Changes

Backend

  • GraphQL schema: agentRuntimeArn field on Application type and ManageApplicationInput, model made nullable
  • genai_core/applications.py: agent ARN validation (strict regex), model-or-agent-required logic in validate_request, agent ARN stored/returned in CRUD operations
  • routes/applications.py: Pydantic models updated with Optional[str] model and agentRuntimeArn with ARN pattern validation
  • send-query-lambda-resolver: routes agent-based applications to modelInterface: "agent" (set server-side), model-based to langchain. Passes modelName, provider, and modelKwargs to agent when configured
  • Bug fix: ConsiseSystemPromptCondenseSystemPrompt typo in update_application

Frontend

  • Agent selector in application form (filters by READY status)
  • Model and model settings remain available when agent is selected (agent receives them in payload)
  • Dynamic modelInterface in chat-input-panel based on application config

Testing

  • 24 unit tests (17 route-level + 7 validate_request including ARN injection attempt)
  • 10 integration tests (6 existing model-based + 4 agent: create, get, query with content verification, delete)

How it works

  1. Admin creates an Application, selects an AgentCore agent (and optionally a model + settings)
  2. When a user sends a message through the Application, the send-query resolver sets modelInterface: "agent" server-side
  3. SNS routes the message to the Bedrock Agents SQS queue
  4. The Bedrock Agents Lambda invokes the agent via AgentCore with the full payload (including model info and kwargs)
  5. Agent streams SSE responses back through the existing WebSocket pipeline

@michaelraskansky michaelraskansky marked this pull request as ready for review March 11, 2026 14:29
@michaelraskansky michaelraskansky marked this pull request as draft March 11, 2026 14:29
Allow admins to configure an Application with an AgentCore agent
instead of a direct LLM model. When a user chats through an
agent-based application, the message is routed to the Bedrock
Agents interface automatically.

Changes:
- Add agentRuntimeArn field to GraphQL schema, DynamoDB, and API
- Route agent-based app messages to bedrock agents interface
  (modelInterface set server-side, not from client)
- Agent selector in application form with model/agent mutual exclusivity
- ARN validation at Pydantic and data layers
- Fix ConsiseSystemPrompt typo in update_application (pre-existing bug)

Tests: 24 passing (13 new agent tests + 11 existing updated)
@michaelraskansky michaelraskansky force-pushed the feature/agentcore-applications branch from ed0551f to d7b193a Compare March 11, 2026 14:31
@michaelraskansky michaelraskansky marked this pull request as ready for review March 11, 2026 14:40
Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

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

The hardcoded AGENT_RUNTIME_ARN in application_test.py (line AGENT_RUNTIME_ARN = "arn:aws:bedrock-agentcore:eu-central-1:481665129290:runtime/...") contains what appears to be a real AWS account ID in a public repository — this should be replaced with an environment variable or a placeholder value pulled from test configuration, similar to how other test fixtures handle account-specific resources.

In applications.py, both model and agentRuntimeArn are now Optional on CreateApplicationRequest and UpdateApplicationRequest, but there's no cross-field validator (e.g., Pydantic's @model_validator) enforcing that exactly one of the two is provided. As written, a request with neither field set would pass validation and likely cause a confusing downstream failure, and a request with both set simultaneously has undefined behavior.

The ARN_REGEX = r"^[A-Za-z0-9-_.:/]+$" is quite permissive — it would accept arbitrary strings like abc:123 that are structurally nothing like an ARN. Consider anchoring it to the expected Bedrock AgentCore ARN prefix (e.g., ^arn:aws:bedrock-agentcore:[a-z0-9-]+:\d{12}:runtime/[\w-]+$) so validation catches malformed values early at the API boundary rather than letting them propagate to DynamoDB or downstream calls.

- Fix ESLint exhaustive-deps warning in application-form.tsx
- Replace hardcoded AWS account ID with placeholder in test
- Add @model_validator for model/agentRuntimeArn mutual exclusivity
- Tighten ARN_REGEX to match Bedrock AgentCore ARN format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants