Skip to content

Commit bf52e45

Browse files
improve agentcore docs (#20135)
1 parent cfd9c50 commit bf52e45

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

docs/examples/memory/agentcore_memory_sample.ipynb

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,38 @@
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
34-
"%pip install llama-index llama-index-memory-bedrock-agentcore"
34+
"%pip install llama-index llama-index-memory-bedrock-agentcore llama-index-llms-bedrock-converse"
3535
]
3636
},
3737
{
3838
"cell_type": "markdown",
39-
"id": "18cf5e60",
39+
"id": "130ba50b",
4040
"metadata": {},
4141
"source": [
42-
"Additionally, you can install the following requirements to follow along with the provided example. The yahoo finance tool is used in the example & the bedrock converse integration is used as the LLM for the FunctionAgent"
43-
]
44-
},
45-
{
46-
"cell_type": "code",
47-
"execution_count": null,
48-
"id": "149b4dd8-5cd9-461e-b9cc-cc878034ea83",
49-
"metadata": {},
50-
"outputs": [],
51-
"source": [
52-
"%pip install llama-index-tools-yahoo-finance llama-index-llms-bedrock-converse"
42+
"### Bedrock AgentCore Setup Pre-Requisites\n",
43+
"\n",
44+
"1. AWS account with Bedrock AgentCore access\n",
45+
"2. Configured AWS credentials (boto3)\n",
46+
"3. Created memory resource in AWS Bedrock AgentCore\n",
47+
"4. Required IAM permissions:\n",
48+
" 1. bedrock-agentcore:CreateEvent\n",
49+
" 2. bedrock-agentcore:ListEvents\n",
50+
" 3. bedrock-agentcore:RetrieveMemories"
5351
]
5452
},
5553
{
5654
"cell_type": "markdown",
5755
"id": "0df5a87e",
5856
"metadata": {},
5957
"source": [
60-
"Initialize the AgentCore Memory context & AgentCore memory classes"
58+
"## Setup\n",
59+
"\n",
60+
"Create an instance of AgentCoreMemoryContext to setup the memory resources that you will need for building an agent.\n",
61+
" 1. Actor id → This is a required field and it is the identifier of the actor (could be an agent or the end-user).\n",
62+
" 2. Memory id → This is a required field and it is the identifier of the memory store.\n",
63+
" 3. Session id → This is a required field and it is the unique identifier of a particular conversation.\n",
64+
" 4. Namespace → This is an optional field and it is used to determine how to extract long term memories. By default it will use “/” as the namespace.\n",
65+
" 5. Memory strategy id → This is an optional field and it is the identifier for a memory strategy."
6166
]
6267
},
6368
{
@@ -87,7 +92,9 @@
8792
"id": "7366bdc7",
8893
"metadata": {},
8994
"source": [
90-
"Initialize the FunctionAgent or ReActAgent with any tool and LLM."
95+
"Initialize the FunctionAgent or ReActAgent with any tool and LLM.\n",
96+
"\n",
97+
"Below we define some dummy tools to have the agent interact with."
9198
]
9299
},
93100
{
@@ -99,13 +106,32 @@
99106
"source": [
100107
"from llama_index.llms.bedrock_converse import BedrockConverse\n",
101108
"from llama_index.core.agent.workflow import FunctionAgent\n",
102-
"from llama_index.tools.yahoo_finance import YahooFinanceToolSpec\n",
109+
"from llama_index.core.tools import FunctionTool\n",
110+
"\n",
111+
"\n",
112+
"async def call_fn(name: str, message: str):\n",
113+
" \"\"\"Call the provided name.\n",
114+
" Args:\n",
115+
" name: str (Name of the person, will lookup their phone number)\n",
116+
" message: str (Message to send)\n",
117+
" \"\"\"\n",
118+
" print(f\"Called {name} and left a message.\")\n",
119+
"\n",
120+
"\n",
121+
"async def email_fn(email: str, message: str):\n",
122+
" \"\"\"Email the provided name.\n",
123+
" Args:\n",
124+
" email: str (Email to send to)\n",
125+
" message: str (Body of the email)\n",
126+
" \"\"\"\n",
127+
" print(f\"Emailing {email} with the provided message.\")\n",
128+
"\n",
103129
"\n",
104130
"llm = BedrockConverse(model=\"us.anthropic.claude-sonnet-4-20250514-v1:0\")\n",
105131
"\n",
106-
"finance_tool_spec = YahooFinanceToolSpec()\n",
132+
"\n",
107133
"agent = FunctionAgent(\n",
108-
" tools=finance_tool_spec.to_tool_list(),\n",
134+
" tools=[email_fn, call_fn],\n",
109135
" llm=llm,\n",
110136
")"
111137
]
@@ -126,7 +152,8 @@
126152
"outputs": [],
127153
"source": [
128154
"response = await agent.run(\n",
129-
" \"What is the stock price for Amazon?\", memory=agentcore_memory\n",
155+
" \"Please email johan@coolcompany.com and tell him that his appointement has been moved to 3 PM January 10th, 2025.\",\n",
156+
" memory=agentcore_memory,\n",
130157
")\n",
131158
"\n",
132159
"print(str(response))"
@@ -148,16 +175,26 @@
148175
"outputs": [],
149176
"source": [
150177
"response = await agent.run(\n",
151-
" \"What stock prices have I asked for?\", memory=agentcore_memory\n",
178+
" \"Who have I emailed recently?\", memory=agentcore_memory\n",
152179
")\n",
153180
"\n",
154181
"print(str(response))"
155182
]
183+
},
184+
{
185+
"cell_type": "markdown",
186+
"id": "fa55ebd9",
187+
"metadata": {},
188+
"source": [
189+
"## References\n",
190+
"\n",
191+
"- [Bedrock AgentCore Memory Documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-getting-started.html)"
192+
]
156193
}
157194
],
158195
"metadata": {
159196
"kernelspec": {
160-
"display_name": "Python 3 (ipykernel)",
197+
"display_name": "llama_index",
161198
"language": "python",
162199
"name": "python3"
163200
},

0 commit comments

Comments
 (0)