Skip to content

Commit 2da7a27

Browse files
committed
Update examples, remove reference to skills
1 parent ca25b90 commit 2da7a27

3 files changed

Lines changed: 58 additions & 24 deletions

File tree

01-tutorials/01-AgentCore-runtime/12-coding-agents/03-codex-with-s3-files-openai-api-key/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ Deploys Codex CLI as an HTTP agent on AWS Bedrock AgentCore Runtime, with an S3
3030
│ (agentcore-<account-id>) │
3131
│ │
3232
│ agents/ │
33-
│ ├── skills/
33+
│ ├── scripts/
3434
│ ├── results/ │
3535
│ └── ... │
3636
└──────────────────────────────┘
3737
```
3838

39-
Multiple runtime sessions mount the same S3 Files file system, enabling agents to share skills, results, and data across independent invocations.
39+
Multiple runtime sessions mount the same S3 Files file system, enabling agents to share scripts, results, and data across independent invocations.
4040

4141
```
4242
CloudFormation stack (cfn-vpc.yaml):
@@ -146,24 +146,31 @@ python update.py
146146

147147
### Step 3 — Invoke the agent
148148

149-
Send a prompt to the deployed agent. The first call creates a new session; subsequent calls can reuse the session ID for conversation continuity.
149+
Send a prompt to the deployed agent. The first call creates a new session; subsequent calls can reuse the session ID and Codex thread ID for conversation continuity.
150150

151-
**Session A** — create a shared skill on the persistent filesystem:
151+
**Session A** — create a shared resource on the persistent filesystem:
152152

153153
```bash
154-
python invoke.py "can u create a new skill, to review python code? This skill should be created into /mnt/s3files/skills/"
154+
python invoke.py "Write a file at /mnt/s3files/scripts/python_review.md with a Python code review checklist. Use the shell to create the directory and write the file directly."
155155
```
156156

157157
Continue the conversation within the same session:
158158

159159
```bash
160-
python invoke.py --session <session-a-id> "now add unit tests for that skill"
160+
python invoke.py --session <session-id> --codex-session <codex-thread-id> "can you review python code, what standards are you going to use?"
161161
```
162162

163-
**Session B** — a completely new session accesses the same filesystem and uses the skill created by Session A:
163+
View the standards defined in the persistent file:
164164

165165
```bash
166-
python invoke.py "list the skills available in /mnt/s3files/skills/ and use the python review skill to review this code: def add(a,b): return a+b"
166+
python invoke.py --session <session-id> --codex-session <codex-thread-id> "what is inside /mnt/s3files/scripts/python_review.md, read it"
167+
```
168+
169+
**Session B** — a completely new session accesses the same filesystem:
170+
171+
```bash
172+
# New session automatically sees the same /mnt/s3files content
173+
python invoke.py "list the files in /mnt/s3files/scripts/ and show me the python_review.md checklist"
167174
```
168175

169176
Both sessions share `/mnt/s3files`, so anything written by one session is immediately available to others.

01-tutorials/01-AgentCore-runtime/12-coding-agents/03-codex-with-s3-files-openai-api-key/invoke.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def load_config() -> dict:
5050
sys.exit(1)
5151

5252

53-
def invoke(runtime_arn: str, prompt: str, region: str, session_id: str = None) -> dict:
53+
def invoke(runtime_arn: str, prompt: str, region: str, session_id: str = None, codex_session_id: str = None) -> dict:
5454
client = boto3.client(
5555
"bedrock-agentcore",
5656
region_name=region,
@@ -61,6 +61,8 @@ def invoke(runtime_arn: str, prompt: str, region: str, session_id: str = None) -
6161
session_id = str(uuid.uuid4())
6262

6363
payload_data = {"prompt": prompt}
64+
if codex_session_id:
65+
payload_data["sessionId"] = codex_session_id
6466

6567
try:
6668
response = client.invoke_agent_runtime(
@@ -84,6 +86,7 @@ def invoke(runtime_arn: str, prompt: str, region: str, session_id: str = None) -
8486
print(f" Status: {response.get('statusCode', 'N/A')}")
8587

8688
body["_runtimeSessionId"] = runtime_session
89+
body["_codexSessionId"] = body.get("sessionId")
8790
return body
8891

8992

@@ -94,12 +97,18 @@ def main():
9497

9598
args = sys.argv[1:]
9699
session_id = None
100+
codex_session_id = None
97101

98102
if "--session" in args:
99103
idx = args.index("--session")
100104
session_id = args[idx + 1]
101105
args = args[:idx] + args[idx + 2:]
102106

107+
if "--codex-session" in args:
108+
idx = args.index("--codex-session")
109+
codex_session_id = args[idx + 1]
110+
args = args[:idx] + args[idx + 2:]
111+
103112
if args:
104113
prompts = [" ".join(args)]
105114
else:
@@ -111,19 +120,23 @@ def main():
111120
print(f"Invoking agent: {runtime_arn}")
112121
if session_id:
113122
print(f"Resuming session: {session_id}")
123+
if codex_session_id:
124+
print(f"Resuming Codex thread: {codex_session_id}")
114125
print()
115126

116127
for prompt in prompts:
117128
print(f"--- Prompt: {prompt}")
118-
result = invoke(runtime_arn, prompt, region, session_id)
129+
result = invoke(runtime_arn, prompt, region, session_id, codex_session_id)
119130
print(f"--- Response:\n{result.get('response', result)}")
120131
session_id = result.get("_runtimeSessionId", session_id)
121-
print(f"--- Session ID: {session_id}")
132+
codex_session_id = result.get("_codexSessionId", codex_session_id)
133+
print(f"--- Session ID: {session_id}")
134+
print(f"--- Codex thread ID: {codex_session_id}")
122135
print()
123136

124-
if session_id:
137+
if session_id and codex_session_id:
125138
print("To continue this conversation:")
126-
print(f" python invoke.py --session {session_id} \"your next prompt\"")
139+
print(f" python invoke.py --session {session_id} --codex-session {codex_session_id} \"your next prompt\"")
127140

128141

129142
if __name__ == "__main__":

01-tutorials/01-AgentCore-runtime/12-coding-agents/03-codex-with-s3-files-openai-api-key/server.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function runCodex(prompt, sessionId) {
77
return new Promise((resolve, reject) => {
88
let args;
99
if (sessionId) {
10-
args = ["exec", "resume", sessionId, prompt, "--json", "--sandbox", "danger-full-access", "--skip-git-repo-check"];
10+
args = ["exec", "resume", "--json", "-c", 'sandbox_mode="danger-full-access"', sessionId, prompt];
1111
} else {
1212
args = ["exec", prompt, "--json", "--sandbox", "danger-full-access", "--skip-git-repo-check"];
1313
}
@@ -29,22 +29,36 @@ function runCodex(prompt, sessionId) {
2929
proc.stderr.on("data", (d) => (stderr += d));
3030

3131
proc.on("close", (code) => {
32-
console.log(`[runCodex] exited code=${code} stderr="${stderr}" stdout="${stdout.slice(0, 200)}"`);
32+
console.log(`[runCodex] exited code=${code}`);
33+
console.log(`[runCodex] stderr: ${stderr}`);
34+
console.log(`[runCodex] stdout: ${stdout}`);
3335
if (code !== 0) {
3436
reject(new Error(`codex exited ${code}: ${stderr}`));
3537
return;
3638
}
37-
// --json emits one JSON object per line, last one has the result
39+
// --json emits one JSON object per line
40+
// thread_id is in the "thread.started" line; response text in "item.completed"
3841
const lines = stdout.trim().split("\n").filter(Boolean);
39-
try {
40-
const last = JSON.parse(lines[lines.length - 1]);
41-
resolve({
42-
response: last.result || last.message || stdout.trim(),
43-
sessionId: last.session_id || null,
44-
});
45-
} catch {
46-
resolve({ response: stdout.trim(), sessionId: null });
42+
let threadId = null;
43+
let responseText = null;
44+
for (const line of lines) {
45+
try {
46+
const obj = JSON.parse(line);
47+
if (obj.type === "thread.started" && obj.thread_id) {
48+
threadId = obj.thread_id;
49+
}
50+
if (obj.type === "item.completed" && obj.item && obj.item.text) {
51+
responseText = obj.item.text;
52+
}
53+
} catch {
54+
// skip non-JSON lines
55+
}
4756
}
57+
console.log(`[runCodex] thread_id=${threadId || "(none)"}`);
58+
resolve({
59+
response: responseText || stdout.trim(),
60+
sessionId: threadId,
61+
});
4862
});
4963
proc.on("error", reject);
5064
});

0 commit comments

Comments
 (0)