Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/cli/commands/add/__tests__/add-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,74 @@ describe('add agent command', () => {
const agent = projectSpec.runtimes.find((a: { name: string }) => a.name === agentName);
expect(agent, 'Agent should be in agentcore.json').toBeTruthy();
expect(agent.codeLocation.includes(codeDir), `codeLocation should reference ${codeDir}`).toBeTruthy();
expect(agent.entrypoint).toBe('main.py');
expect(agent.runtimeVersion).toBe('PYTHON_3_14');
});

it('uses TypeScript defaults for BYO agents', async () => {
const agentName = `ByoTypeScriptAgent${Date.now()}`;
const codeDir = 'existing-typescript-agent';

const result = await runCLI(
[
'add',
'agent',
'--name',
agentName,
'--type',
'byo',
'--code-location',
codeDir,
'--language',
'TypeScript',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--json',
],
projectDir
);

expect(result.exitCode, `stdout: ${result.stdout}`).toBe(0);

const projectSpec = JSON.parse(await readFile(join(projectDir, 'agentcore/agentcore.json'), 'utf-8'));
const agent = projectSpec.runtimes.find((a: { name: string }) => a.name === agentName);
expect(agent.entrypoint).toBe('main.js');
expect(agent.runtimeVersion).toBe('NODE_22');
});

it('preserves Python defaults for BYO agents with Other language', async () => {
const agentName = `ByoOtherAgent${Date.now()}`;
const codeDir = 'existing-other-agent';

const result = await runCLI(
[
'add',
'agent',
'--name',
agentName,
'--type',
'byo',
'--code-location',
codeDir,
'--language',
'Other',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--json',
],
projectDir
);

expect(result.exitCode, `stdout: ${result.stdout}`).toBe(0);

const projectSpec = JSON.parse(await readFile(join(projectDir, 'agentcore/agentcore.json'), 'utf-8'));
const agent = projectSpec.runtimes.find((a: { name: string }) => a.name === agentName);
expect(agent.entrypoint).toBe('main.py');
expect(agent.runtimeVersion).toBe('PYTHON_3_14');
});

it('requires code-location for BYO path', async () => {
Expand Down
8 changes: 5 additions & 3 deletions src/cli/primitives/AgentPrimitive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import type {
import {
AgentEnvSpecSchema,
CREDENTIAL_PROVIDERS,
DEFAULT_PYTHON_VERSION,
DEFAULT_ENTRYPOINT_BY_LANGUAGE,
DEFAULT_RUNTIME_BY_LANGUAGE,
LIFECYCLE_TIMEOUT_MAX,
LIFECYCLE_TIMEOUT_MIN,
} from '../../schema';
Expand Down Expand Up @@ -720,13 +721,14 @@ export class AgentPrimitive extends BasePrimitive<AddAgentOptions, RemovableReso
: undefined;

const lifecycleConfiguration = this.buildLifecycleConfig(options);
const defaultLanguage = options.language === 'TypeScript' ? 'TypeScript' : 'Python';

const agent: AgentEnvSpec = {
name: options.name,
build: options.buildType,
entrypoint: (options.entrypoint ?? 'main.py') as FilePath,
entrypoint: (options.entrypoint ?? DEFAULT_ENTRYPOINT_BY_LANGUAGE[defaultLanguage]) as FilePath,
codeLocation: codeLocation as DirectoryPath,
runtimeVersion: DEFAULT_PYTHON_VERSION,
runtimeVersion: DEFAULT_RUNTIME_BY_LANGUAGE[defaultLanguage],
protocol,
networkMode,
...(networkMode === 'VPC' &&
Expand Down
Loading