Skip to content

Commit e6aeeb3

Browse files
AWSChrisChristopher Reesrlhagerm
authored
Amazon Bedrock playlist flow (#7358)
Co-authored-by: Christopher Rees <[email protected]> Co-authored-by: Rachel Hagerman <[email protected]>
1 parent dad427d commit e6aeeb3

18 files changed

+2663
-0
lines changed

.doc_gen/metadata/bedrock-agent_metadata.yaml

+224
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ bedrock-agent_PrepareAgent:
185185
- python.example_code.bedrock-agent.PrepareAgent
186186
services:
187187
bedrock-agent: {PrepareAgent}
188+
189+
188190
bedrock-agent_GettingStartedWithBedrockAgents:
189191
title: An end-to-end example showing how to create and invoke &BRA; using an &AWS; SDK
190192
title_abbrev: Create and invoke an agent
@@ -209,3 +211,225 @@ bedrock-agent_GettingStartedWithBedrockAgents:
209211
services:
210212
bedrock-agent: {CreateAgent, CreateAgentActionGroup, CreateAgentAlias, DeleteAgent, DeleteAgentAlias, GetAgent, ListAgentActionGroups,
211213
ListAgents, ListAgentKnowledgeBases, PrepareAgent}
214+
215+
216+
217+
bedrock-agent_GettingStartedWithBedrockFlows:
218+
title: An end-to-end example showing how to create and invoke an Amazon Bedrock flow using an &AWS; SDK
219+
title_abbrev: Create and invoke a flow
220+
synopsis_list:
221+
- Create an execution role for the flow.
222+
- Create the flow.
223+
- Deploy the fully configured flow.
224+
- Invoke the flow with user-provided prompts.
225+
- Delete all created resources.
226+
category: Scenarios
227+
languages:
228+
Python:
229+
versions:
230+
- sdk_version: 3
231+
github: python/example_code/bedrock-agent
232+
excerpts:
233+
- description: Generates a music playlist based on user-specified genre and number of songs.
234+
snippet_tags:
235+
- python.example_code.bedrock-agent-runtime.Scenario_GettingStartedBedrockFlows
236+
- python.example_code.bedrock-agent-runtime.flow_invoke_flow
237+
- python.example_code.bedrock-agent-runtime.run_playlist_flow
238+
- python.example_code.bedrock-agent-runtime.Scenario_GettingStartedBedrockFlows_iam_role
239+
240+
services:
241+
bedrock-agent: {CreateFlow, CreateFlowAlias, CreateFlowVersion, DeleteFlow, DeleteFlowVersion, DeleteFlowAlias, GetFlow, GetFlowAlias,
242+
GetFlowVersion, PrepareFlow}
243+
bedrock-agent-runtime: {InvokeFlow}
244+
245+
246+
bedrock-agent_CreateFlow:
247+
languages:
248+
Python:
249+
versions:
250+
- sdk_version: 3
251+
github: python/example_code/bedrock-agent
252+
excerpts:
253+
- description: Create an Amazon Bedrock flow.
254+
snippet_tags:
255+
- python.example_code.bedrock-agent.create_flow
256+
services:
257+
bedrock-agent: {CreateFlow}
258+
259+
bedrock-agent_PrepareFlow:
260+
languages:
261+
Python:
262+
versions:
263+
- sdk_version: 3
264+
github: python/example_code/bedrock-agent
265+
excerpts:
266+
- description: Prepare an Amazon Bedrock flow.
267+
snippet_tags:
268+
- python.example_code.bedrock-agent.prepare_flow
269+
services:
270+
bedrock-agent: {PrepareFlow}
271+
272+
bedrock-agent_UpdateFlow:
273+
languages:
274+
Python:
275+
versions:
276+
- sdk_version: 3
277+
github: python/example_code/bedrock-agent
278+
excerpts:
279+
- description: Update an Amazon Bedrock Flow.
280+
snippet_tags:
281+
- python.example_code.bedrock-agent.update_flow
282+
services:
283+
bedrock-agent: {UpdateFlow}
284+
285+
bedrock-agent_DeleteFlow:
286+
languages:
287+
Python:
288+
versions:
289+
- sdk_version: 3
290+
github: python/example_code/bedrock-agent
291+
excerpts:
292+
- description: Delete an Amazon Bedrock flow.
293+
snippet_tags:
294+
- python.example_code.bedrock-agent.delete_flow
295+
services:
296+
bedrock-agent: {DeleteFlow}
297+
298+
bedrock-agent_GetFlow:
299+
languages:
300+
Python:
301+
versions:
302+
- sdk_version: 3
303+
github: python/example_code/bedrock-agent
304+
excerpts:
305+
- description: Get an Amazon Bedrock flow.
306+
snippet_tags:
307+
- python.example_code.bedrock-agent.get_flow
308+
services:
309+
bedrock-agent: {GetFlow}
310+
311+
bedrock-agent_ListFlows:
312+
languages:
313+
Python:
314+
versions:
315+
- sdk_version: 3
316+
github: python/example_code/bedrock-agent
317+
excerpts:
318+
- description: List Amazon Bedrock flows.
319+
snippet_tags:
320+
- python.example_code.bedrock-agent.list_flows
321+
322+
services:
323+
bedrock-agent: {ListFlows}
324+
325+
bedrock-agent_CreateFlowAlias:
326+
languages:
327+
Python:
328+
versions:
329+
- sdk_version: 3
330+
github: python/example_code/bedrock-agent
331+
excerpts:
332+
- description: Create an alias for an Amazon Bedrock flow.
333+
snippet_tags:
334+
- python.example_code.bedrock-agent.create_flow_alias
335+
336+
services:
337+
bedrock-agent: {CreateFlowAlias}
338+
339+
bedrock-agent_UpdateFlowAlias:
340+
languages:
341+
Python:
342+
versions:
343+
- sdk_version: 3
344+
github: python/example_code/bedrock-agent
345+
excerpts:
346+
- description: Update an alias for an Amazon Bedrock flow.
347+
snippet_tags:
348+
- python.example_code.bedrock-agent.update_flow_alias
349+
350+
services:
351+
bedrock-agent: {UpdateFlowAlias}
352+
353+
bedrock-agent_DeleteFlowAlias:
354+
languages:
355+
Python:
356+
versions:
357+
- sdk_version: 3
358+
github: python/example_code/bedrock-agent
359+
excerpts:
360+
- description: Delete an alias for an Amazon Bedrock flow.
361+
snippet_tags:
362+
- python.example_code.bedrock-agent.delete_flow_alias
363+
364+
services:
365+
bedrock-agent: {DeleteFlowAlias}
366+
367+
bedrock-agent_ListFlowAliases:
368+
languages:
369+
Python:
370+
versions:
371+
- sdk_version: 3
372+
github: python/example_code/bedrock-agent
373+
excerpts:
374+
- description: List the aliases for an Amazon Bedrock flow.
375+
snippet_tags:
376+
- python.example_code.bedrock-agent.list_flow_aliases
377+
378+
services:
379+
bedrock-agent: {ListFlowAliases}
380+
381+
bedrock-agent_CreateFlowVersion:
382+
languages:
383+
Python:
384+
versions:
385+
- sdk_version: 3
386+
github: python/example_code/bedrock-agent
387+
excerpts:
388+
- description: Create a version of an Amazon Bedrock flow.
389+
snippet_tags:
390+
- python.example_code.bedrock-agent.create_flow_version
391+
392+
services:
393+
bedrock-agent: {CreateFlowVersion}
394+
395+
bedrock-agent_GetFlowVersion:
396+
languages:
397+
Python:
398+
versions:
399+
- sdk_version: 3
400+
github: python/example_code/bedrock-agent
401+
excerpts:
402+
- description: Get a version of an Amazon Bedrock flow.
403+
snippet_tags:
404+
- python.example_code.bedrock-agent.get_flow_version
405+
406+
services:
407+
bedrock-agent: {GetFlowVersion}
408+
409+
bedrock-agent_DeleteFlowVersion:
410+
languages:
411+
Python:
412+
versions:
413+
- sdk_version: 3
414+
github: python/example_code/bedrock-agent
415+
excerpts:
416+
- description: Delete a version of an Amazon Bedrock flow.
417+
snippet_tags:
418+
- python.example_code.bedrock-agent.delete_flow_version
419+
420+
services:
421+
bedrock-agent: {DeleteFlowVersion}
422+
423+
bedrock-agent_ListFlowVersions:
424+
languages:
425+
Python:
426+
versions:
427+
- sdk_version: 3
428+
github: python/example_code/bedrock-agent
429+
excerpts:
430+
- description: List the versions of an Amazon Bedrock flow.
431+
snippet_tags:
432+
- python.example_code.bedrock-agent.list_flow_versions
433+
434+
services:
435+
bedrock-agent: {ListFlowVersions}

python/example_code/bedrock-agent/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,31 @@ Code excerpts that show you how to call individual service functions.
4848
- [ListAgentKnowledgeBases](bedrock_agent_wrapper.py#L237)
4949
- [ListAgents](bedrock_agent_wrapper.py#L185)
5050
- [PrepareAgent](bedrock_agent_wrapper.py#L266)
51+
- [InvokeFlow](flows/run_flow.py#L23)
52+
- [CreateFlow](flows/flow.py#L18)
53+
- [PrepareFlow](flows/flow.py#L58)
54+
- [UpdateFlow](flows/flow.py#L112)
55+
- [DeleteFlow](flows/flow.py#L156)
56+
- [GetFlow](flows/flow.py#L192)
57+
- [ListFlows](flows/flow.py#L229)
58+
- [CreateFlowVersion](flows/flow_version.py#L18)
59+
- [GetFlowVersion](flows/flow_version.py#L54)
60+
- [DeleteFlowVersion](flows/flow_version.py#L91)
61+
- [ListFlowVersions](flows/flow_version.py#L128)
62+
- [CreateFlowAlias](flows/flow_alias.py#L15)
63+
- [UpdateFlowAlias](flows/flow_alias.py#L55)
64+
- [DeleteFlowAlias](flows/flow_alias.py#L98)
65+
- [ListFlowAliases](flows/flow_alias.py#L132)
66+
67+
5168

5269
### Scenarios
5370

5471
Code examples that show you how to accomplish a specific task by calling multiple
5572
functions within the same service.
5673

5774
- [Create and invoke an agent](scenario_get_started_with_agents.py)
75+
- [Create and invoke a flow](flows/playlist_flow.py)
5876

5977

6078
<!--custom.examples.start-->
@@ -95,6 +113,37 @@ python scenario_get_started_with_agents.py
95113
<!--custom.scenarios.bedrock-agent_GettingStartedWithBedrockAgents.start-->
96114
<!--custom.scenarios.bedrock-agent_GettingStartedWithBedrockAgents.end-->
97115

116+
117+
#### Create and invoke a flow
118+
119+
Shows how to create a simple flow that generates music playlists.
120+
The flow includes a prompt node that generates a playlist for a chosen genre
121+
and number of songs. The example creates the nodes and permissions
122+
for the flow.
123+
124+
Start the example by running the following at a command prompt:
125+
126+
```
127+
python flows/playlist_flow.py
128+
```
129+
When prompted, enter the genre of music and the number of songs you want
130+
in the playlist.
131+
Optionally, the script can delete the resources that it creates. If you want to use the flow later, such as in the Amazon Bedrock console, enter `n` when the script prompts you to delete resources. Note that you will then need to manually delete the resources.
132+
133+
134+
135+
#### List flows
136+
137+
Shows how to List Amazon Bedrock flows, versions of a flow, and aliases of a flow.
138+
139+
Start the example by running the following at a command prompt:
140+
141+
```
142+
python flows/list_flows.py
143+
```
144+
The example first lists the flows in the current AWS Region. It
145+
then prompts for a flow ID, which you can get from the list of flows. Finally, the example lists the flow versions and flow aliases for the flow ID that you entered.
146+
98147
### Tests
99148

100149
⚠ Running tests might result in charges to your AWS account.

0 commit comments

Comments
 (0)