feat: allow AgentCore agent selection in Applications#726
feat: allow AgentCore agent selection in Applications#726michaelraskansky wants to merge 2 commits intoaws-samples:mainfrom
Conversation
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)
ed0551f to
d7b193a
Compare
JiwaniZakir
left a comment
There was a problem hiding this comment.
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
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
agentRuntimeArnfield onApplicationtype andManageApplicationInput,modelmade nullablevalidate_request, agent ARN stored/returned in CRUD operationsOptional[str]model andagentRuntimeArnwith ARN pattern validationmodelInterface: "agent"(set server-side), model-based tolangchain. PassesmodelName,provider, andmodelKwargsto agent when configuredConsiseSystemPrompt→CondenseSystemPrompttypo inupdate_applicationFrontend
READYstatus)modelInterfacein chat-input-panel based on application configTesting
How it works
modelInterface: "agent"server-side