You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(py#strands-agent): extract session ID from header instead of request body (#557)
* fix(py#strands-agent): extract session ID from header instead of request body
Align the Python strands agent with the TypeScript implementation by reading
the session ID from the `x-amzn-bedrock-agentcore-runtime-session-id` HTTP
header (the Bedrock AgentCore standard) instead of requiring it in the POST
request body. A random UUID is generated as fallback when the header is absent.
Also renames the input field from `prompt` to `message` for consistency with
the TypeScript agent's input schema.
* docs: update translations
* fix(py#strands-agent): use Request to extract session ID header
Use FastAPI's Request object instead of Header() dependency to extract
the session ID from the x-amzn-bedrock-agentcore-runtime-session-id
header. This avoids the header appearing in the OpenAPI spec, which
caused @hey-api/openapi-ts to generate invalid TypeScript types for the
long hyphenated header name.
* docs: update translations
---------
Co-authored-by: nx-plugin-for-aws <nx-plugin@amazon.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
The default `InvokeInput` model accepts a prompt and session ID.
194
+
The default `InvokeInput` model accepts a message.
195
195
196
196
```python
197
197
from pydantic import BaseModel
198
198
199
199
classInvokeInput(BaseModel):
200
-
prompt: str
201
-
session_id: str
200
+
message: str
202
201
```
203
202
204
203
You can extend this model to include any additional fields your agent needs.
205
204
205
+
The session ID is extracted from the `x-amzn-bedrock-agentcore-runtime-session-id` HTTP header, consistent with the [Bedrock AgentCore Runtime session contract](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html). If the header is not provided, a random UUID is generated as a fallback.
206
+
206
207
:::caution[Code Organization]
207
208
You will likely want to abstract some or all of the session ID from the caller if users are to invoke your agent directly. For example, you may use the authenticated user ID as part of the session ID.
208
209
@@ -302,7 +303,7 @@ To invoke an Agent running locally via the `<your-agent-name>-serve` target, you
302
303
303
304
```bash
304
305
curl -N -X POST http://localhost:8081/invocations \
305
-
-d '{"prompt": "what is 3 + 5?", "session_id": "abcdefghijklmnopqrstuvwxyz0123456789"}' \
306
+
-d '{"message": "what is 3 + 5?"}' \
306
307
-H "Content-Type: application/json"
307
308
```
308
309
@@ -337,7 +338,7 @@ For Cognito Authentication, pass the Cognito Access Token in the `Authorization`
Copy file name to clipboardExpand all lines: docs/src/content/docs/es/guides/py-strands-agent.mdx
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,18 +191,19 @@ El endpoint de invocación del agente usa modelos [Pydantic](https://docs.pydant
191
191
192
192
#### Definiendo Modelos de Entrada
193
193
194
-
El modelo `InvokeInput` por defecto acepta un prompt y un ID de sesión.
194
+
El modelo `InvokeInput` por defecto acepta un mensaje.
195
195
196
196
```python
197
197
from pydantic import BaseModel
198
198
199
199
classInvokeInput(BaseModel):
200
-
prompt: str
201
-
session_id: str
200
+
message: str
202
201
```
203
202
204
203
Puedes extender este modelo para incluir cualquier campo adicional que tu agente necesite.
205
204
205
+
El ID de sesión se extrae del header HTTP `x-amzn-bedrock-agentcore-runtime-session-id`, de acuerdo con el [contrato de sesión de Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html). Si el header no se proporciona, se genera un UUID aleatorio como alternativa.
206
+
206
207
:::caution[Organización del código]
207
208
Probablemente querrás abstraer parte o todo el ID de sesión del llamador si los usuarios van a invocar tu agente directamente. Por ejemplo, puedes usar el ID de usuario autenticado como parte del ID de sesión.
208
209
@@ -300,7 +301,7 @@ Para invocar un Agente ejecutándose localmente mediante el target `<your-agent-
300
301
301
302
```bash
302
303
curl -N -X POST http://localhost:8081/invocations \
303
-
-d '{"prompt": "what is 3 + 5?", "session_id": "abcdefghijklmnopqrstuvwxyz0123456789"}' \
304
+
-d '{"message": "what is 3 + 5?"}' \
304
305
-H "Content-Type: application/json"
305
306
```
306
307
@@ -335,7 +336,7 @@ Para autenticación Cognito, pasa el Access Token de Cognito en el header `Autho
Copy file name to clipboardExpand all lines: docs/src/content/docs/fr/guides/py-strands-agent.mdx
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,18 +191,19 @@ Le point de terminaison d'invocation de l'agent utilise des modèles [Pydantic](
191
191
192
192
#### Définition des modèles d'entrée
193
193
194
-
Le modèle `InvokeInput` par défaut accepte un prompt et un ID de session.
194
+
Le modèle `InvokeInput` par défaut accepte un message.
195
195
196
196
```python
197
197
from pydantic import BaseModel
198
198
199
199
classInvokeInput(BaseModel):
200
-
prompt: str
201
-
session_id: str
200
+
message: str
202
201
```
203
202
204
203
Vous pouvez étendre ce modèle pour inclure tous les champs supplémentaires dont votre agent a besoin.
205
204
205
+
L'ID de session est extrait de l'en-tête HTTP `x-amzn-bedrock-agentcore-runtime-session-id`, conformément au [contrat de session Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html). Si l'en-tête n'est pas fourni, un UUID aléatoire est généré par défaut.
206
+
206
207
:::caution[Organisation du code]
207
208
Vous voudrez probablement abstraire tout ou partie de l'ID de session de l'appelant si les utilisateurs doivent invoquer votre agent directement. Par exemple, vous pouvez utiliser l'ID utilisateur authentifié comme partie de l'ID de session.
208
209
@@ -302,7 +303,7 @@ Pour invoquer un agent exécuté localement via la cible `<your-agent-name>-serv
302
303
303
304
```bash
304
305
curl -N -X POST http://localhost:8081/invocations \
305
-
-d '{"prompt": "what is 3 + 5?", "session_id": "abcdefghijklmnopqrstuvwxyz0123456789"}' \
306
+
-d '{"message": "what is 3 + 5?"}' \
306
307
-H "Content-Type: application/json"
307
308
```
308
309
@@ -337,7 +338,7 @@ Pour l'authentification Cognito, passez le jeton d'accès Cognito dans l'en-têt
Copy file name to clipboardExpand all lines: docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ Questo configurerà un monorepo NX all'interno della directory `dungeon-adventur
54
54
55
55
Ora possiamo iniziare a creare i diversi sotto-progetti utilizzando `@aws/nx-plugin`.
56
56
57
-
<Asidetype="tip">È una best practice assicurarsi che tutti i file non staged siano committati in Git prima di eseguire qualsiasi generatore. Questo permette di visualizzare le modifiche dopo l'esecuzione tramite `git diff`.</Aside>
57
+
<Asidetype="tip"title="Committa spesso">È una best practice assicurarsi che tutti i file non staged siano committati in Git prima di eseguire qualsiasi generatore. Questo permette di visualizzare le modifiche dopo l'esecuzione tramite `git diff`.</Aside>
58
58
59
59
## Task 2: Creare una Game API
60
60
@@ -454,27 +454,31 @@ Questo crea un agente Strands di esempio e definisce uno strumento di addizione.
454
454
455
455
```python
456
456
# agent/main.py
457
+
import uuid
458
+
457
459
import uvicorn
458
460
from bedrock_agentcore.runtime.models import PingStatus
@@ -1096,7 +1101,7 @@ new ApplicationStage(app, 'dungeon-adventure-infra-sandbox', {
1096
1101
app.synth();
1097
1102
```
1098
1103
1099
-
<Asidetype="tip">Se vedi un errore di import nel tuo IDE, è perché il progetto infrastruttura non ha ancora un riferimento TypeScript configurato nel `tsconfig.json`. Nx è stato [configurato](https://nx.dev/nx-api/js/generators/typescript-sync) per creare questi riferimenti *dinamicamente* ogni volta che viene eseguita una build/compilazione o se esegui manualmente il comando `nx sync`. Per maggiori informazioni consulta la <Linkpath="guides/typescript-project#importing-your-library-code-in-other-projects">guida TypeScript</Link>.</Aside>
1104
+
<Asidetype="tip"title="Correggere errori di import">Se vedi un errore di import nel tuo IDE, è perché il progetto infrastruttura non ha ancora un riferimento TypeScript configurato nel `tsconfig.json`. Nx è stato [configurato](https://nx.dev/nx-api/js/generators/typescript-sync) per creare questi riferimenti *dinamicamente* ogni volta che viene eseguita una build/compilazione o se esegui manualmente il comando `nx sync`. Per maggiori informazioni consulta la <Linkpath="guides/typescript-project#importing-your-library-code-in-other-projects">guida TypeScript</Link>.</Aside>
Il modello `InvokeInput` predefinito accetta un prompt e un ID di sessione.
194
+
Il modello `InvokeInput` predefinito accetta un messaggio.
195
195
196
196
```python
197
197
from pydantic import BaseModel
198
198
199
199
classInvokeInput(BaseModel):
200
-
prompt: str
201
-
session_id: str
200
+
message: str
202
201
```
203
202
204
203
Puoi estendere questo modello per includere qualsiasi campo aggiuntivo di cui il tuo agente ha bisogno.
205
204
205
+
L'ID di sessione viene estratto dall'header HTTP `x-amzn-bedrock-agentcore-runtime-session-id`, coerentemente con il [contratto di sessione di Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html). Se l'header non viene fornito, viene generato un UUID casuale come fallback.
206
+
206
207
:::caution[Organizzazione del codice]
207
208
Probabilmente vorrai astrarre parte o tutto l'ID di sessione dal chiamante se gli utenti devono invocare il tuo agente direttamente. Ad esempio, potresti usare l'ID utente autenticato come parte dell'ID di sessione.
208
209
@@ -302,7 +303,7 @@ Per invocare un Agente in esecuzione localmente tramite il target `<your-agent-n
302
303
303
304
```bash
304
305
curl -N -X POST http://localhost:8081/invocations \
305
-
-d '{"prompt": "what is 3 + 5?", "session_id": "abcdefghijklmnopqrstuvwxyz0123456789"}' \
306
+
-d '{"message": "what is 3 + 5?"}' \
306
307
-H "Content-Type: application/json"
307
308
```
308
309
@@ -337,7 +338,7 @@ Per l'Autenticazione Cognito, passa il Token di Accesso Cognito nell'header `Aut
0 commit comments