fix(cli): vend starter entrypoint for BYO agents (#629)#63
Draft
aidandaly24 wants to merge 1 commit into
Draft
Conversation
When creating a Bring-Your-Own agent (agentcore create or agentcore add agent --type byo), the CLI created an empty code directory and only printed a reminder, leaving new users with nothing to run and a failing agentcore dev until they hand-authored main.py with the correct contract. handleByoPath() now writes a starter entrypoint at the resolved --entrypoint name (defaulting to main.py) only when the file does not already exist, so user code is never overwritten. The stub follows the real AgentCore runtime contract (BedrockAgentCoreApp / @app.entrypoint / app.run), gated on language: a Python stub for Python, a TypeScript stub for TypeScript, and no stub for Other. The reminder text is softened now that a placeholder is vended. Fixes aws#629
Coverage Report
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs aws#629
Issues
Root cause
handleByoPath() only mkdirSyncs the code dir at AgentPrimitive.tsx:672 and vends no entrypoint, vs handleCreatePath() which renders a full template at :603-605 — confirmed byte-identical at v0.20.2 via git diff/show; entrypoint contract (BedrockAgentCoreApp/@app.entrypoint/app.run) verified in vended main.py:52,77,510,671 and SDK app.py:213,644.
The fix
In handleByoPath() after the mkdirSync at AgentPrimitive.tsx:672, write a starter entrypoint file at join(codeDir, options.entrypoint ?? 'main.py') only when it does not already exist (never overwrite user code). The stub MUST follow the real AgentCore contract, NOT a Lambda handler: from bedrock_agentcore.runtime import BedrockAgentCoreApp; app = BedrockAgentCoreApp(); @app.entrypoint def invoke(payload, context): ...; if name == 'main': app.run(). Two required design decisions: (1) BYO supports --language Python/TypeScript/Other (AgentPrimitive.tsx:260) so gate on language — Python stub for Python, optional TS stub for TypeScript, skip for Other; (2) the filename is user-configurable via --entrypoint (AgentPrimitive.tsx:270, resolved at line 714) so write to the resolved entrypoint name, not a hardcoded main.py. Cleanest implementation is a small BYO placeholder asset under src/assets/ plus a renderer in src/cli/templates/ for consistency with the existing template pipeline; the reminder text at CreateScreen.tsx:98-99 and AddFlow.tsx:145-150 can be softened once a placeholder exists. NOTE: the issue's own suggested stub def handler(event, context): return {'statusCode': 200} is WRONG for this runtime and would fail the 'agentcore dev works out of the box' acceptance criterion.
Files touched: /local/home/aidandal/workplace/issues/agentcore-cli/src/cli/primitives/AgentPrimitive.tsx — handleByoPath() (lines 662-743), add placeholder-file write after mkdirSync at line 672 using the entrypoint resolved at line 714. Optionally add a BYO placeholder asset under src/assets/ + renderer in src/cli/templates/. Reminders at src/cli/tui/screens/create/CreateScreen.tsx:98-99 and src/cli/tui/screens/add/AddFlow.tsx:145-150 may be softened.
Validation evidence
The fix was verified by reproducing the original symptom and re-running after the change:
AFTER (fix restored + rebuilt, run by dist/cli/index.mjs):
from bedrock_agentcore.runtime import BedrockAgentCoreApp,app = BedrockAgentCoreApp(),@app.entrypoint def invoke(payload, context),app.run()underif __name__ == "__main__"; contains NOdef handler(event, context).handlerattribute.Test suite: green.
Staged on the fork as a draft for human review. Promote to aws/agentcore-cli after vetting.