|
31 | 31 | "metadata": {}, |
32 | 32 | "outputs": [], |
33 | 33 | "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" |
35 | 35 | ] |
36 | 36 | }, |
37 | 37 | { |
38 | 38 | "cell_type": "markdown", |
39 | | - "id": "18cf5e60", |
| 39 | + "id": "130ba50b", |
40 | 40 | "metadata": {}, |
41 | 41 | "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" |
53 | 51 | ] |
54 | 52 | }, |
55 | 53 | { |
56 | 54 | "cell_type": "markdown", |
57 | 55 | "id": "0df5a87e", |
58 | 56 | "metadata": {}, |
59 | 57 | "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." |
61 | 66 | ] |
62 | 67 | }, |
63 | 68 | { |
|
87 | 92 | "id": "7366bdc7", |
88 | 93 | "metadata": {}, |
89 | 94 | "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." |
91 | 98 | ] |
92 | 99 | }, |
93 | 100 | { |
|
99 | 106 | "source": [ |
100 | 107 | "from llama_index.llms.bedrock_converse import BedrockConverse\n", |
101 | 108 | "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", |
103 | 129 | "\n", |
104 | 130 | "llm = BedrockConverse(model=\"us.anthropic.claude-sonnet-4-20250514-v1:0\")\n", |
105 | 131 | "\n", |
106 | | - "finance_tool_spec = YahooFinanceToolSpec()\n", |
| 132 | + "\n", |
107 | 133 | "agent = FunctionAgent(\n", |
108 | | - " tools=finance_tool_spec.to_tool_list(),\n", |
| 134 | + " tools=[email_fn, call_fn],\n", |
109 | 135 | " llm=llm,\n", |
110 | 136 | ")" |
111 | 137 | ] |
|
126 | 152 | "outputs": [], |
127 | 153 | "source": [ |
128 | 154 | "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", |
130 | 157 | ")\n", |
131 | 158 | "\n", |
132 | 159 | "print(str(response))" |
|
148 | 175 | "outputs": [], |
149 | 176 | "source": [ |
150 | 177 | "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", |
152 | 179 | ")\n", |
153 | 180 | "\n", |
154 | 181 | "print(str(response))" |
155 | 182 | ] |
| 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 | + ] |
156 | 193 | } |
157 | 194 | ], |
158 | 195 | "metadata": { |
159 | 196 | "kernelspec": { |
160 | | - "display_name": "Python 3 (ipykernel)", |
| 197 | + "display_name": "llama_index", |
161 | 198 | "language": "python", |
162 | 199 | "name": "python3" |
163 | 200 | }, |
|
0 commit comments