Skip to content

Commit 4d3ed74

Browse files
committed
edit pass: ai-agents
1 parent 2ce8c59 commit 4d3ed74

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

articles/cosmos-db/ai-agents.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Complex reasoning and planning are the hallmark of advanced autonomous agents. P
8585

8686
- [Reflect and self-critique](https://arxiv.org/abs/2303.11366)
8787

88-
Use *reflexion* agents that verbally reflect on task feedback signals. These agents their own reflective text in an episodic memory buffer to induce better decision-making in subsequent trials.
88+
Use *reflexion* agents that verbally reflect on task feedback signals. These agents maintain their own reflective text in an episodic memory buffer to induce better decision-making in subsequent trials.
8989

9090
### Frameworks
9191

@@ -126,9 +126,7 @@ Pure vector databases tend to be less effective for transactional operations, re
126126
- Limited options for multitenancy.
127127
- Limited security.
128128

129-
## Characteristics of robust AI agents
130-
131-
This section dives deeper into what makes a robust AI agent memory system.
129+
## Characteristics of a robust AI agent memory system
132130

133131
Just as efficient database management systems are critical to the performance of software applications, it's critical to provide LLM-powered agents with relevant and useful information to guide their inference. Robust memory systems enable organizing and storing various kinds of information that the agents can retrieve at inference time.
134132

@@ -162,7 +160,7 @@ At the macro level, memory systems should enable multiple AI agents to collabora
162160

163161
At the same time, the memory system must allow agents to preserve their own persona and characteristics, such as their unique collections of prompts and memories.
164162

165-
## Building a robust memory system for AI agents
163+
## Building a robust AI agent memory system
166164

167165
The preceding characteristics require AI agent memory systems to be highly scalable and swift. Painstakingly weaving together disparate in-memory, relational, and vector databases (as described [earlier](#memory-system-for-ai-agents)) might work for early-stage AI-enabled applications. However, this approach adds complexity and performance bottlenecks that can hamper the performance of advanced autonomous agents.
168166

@@ -186,7 +184,7 @@ Azure Cosmos DB can simplify data management and architecture by integrating mul
186184

187185
Its integrated vector database capabilities can store, index, and query embeddings alongside the corresponding data in natural or programming languages. This capability enables greater data consistency, scale, and performance.
188186

189-
Its flexibility supports the varied modalities and fluid schemas of the metadata, relationships, entities, summaries, chat history, user preferences, sensory data, decisions, facts learned, or other operational data involved in agent workflows. The database automatically indexes all data without requiring schema or index management, which helps AI agents to perform complex queries quickly and efficiently.
187+
Its flexibility supports the varied modalities and fluid schemas of the metadata, relationships, entities, summaries, chat history, user preferences, sensory data, decisions, facts learned, or other operational data involved in agent workflows. The database automatically indexes all data without requiring schema or index management, which helps AI agents perform complex queries quickly and efficiently.
190188

191189
Azure Cosmos DB is fully managed, which eliminates the overhead of database administration tasks like scaling, patching, and backups. Without this overhead, developers can focus on building and optimizing AI agents without worrying about the underlying data infrastructure.
192190

@@ -201,8 +199,8 @@ The five available [consistency levels](consistency-levels.md) (from strong to e
201199
> [!TIP]
202200
> You can choose from two Azure Cosmos DB APIs to build your AI agent memory system:
203201
>
204-
> - Azure Cosmos DB for NoSQL, which provides [three vector search algorithms](nosql/vector-search.md): IVF, HNSW, and DiskANN.
205-
> - vCore-based Azure Cosmos DB for MongoDB, which provides [two vector search algorithms](mongodb/vcore/vector-search.md): IVF and HNSW.
202+
> - Azure Cosmos DB for NoSQL, which provides [three vector search algorithms](nosql/vector-search.md): IVF, HNSW, and DiskANN
203+
> - vCore-based Azure Cosmos DB for MongoDB, which provides [two vector search algorithms](mongodb/vcore/vector-search.md): IVF and HNSW
206204
>
207205
> For information about the availability guarantees for these APIs, see the [service SLAs](https://www.microsoft.com/licensing/docs/view/Service-Level-Agreements-SLA-for-Online-Services).
208206
@@ -212,15 +210,15 @@ This section explores the implementation of an autonomous agent to process trave
212210

213211
Chatbots are a long-standing concept, but AI agents are advancing beyond basic human conversation to carry out tasks based on natural language. These tasks traditionally required coded logic. The AI travel agent in this implementation sample uses the LangChain Agent framework for agent planning, tool usage, and perception.
214212

215-
The AI travel agent's [unified memory system](#memory-can-make-or-break-agents) uses the [vector database](vector-database.md) and document store capabilities of Azure Cosmos DB to address traveler inquiries and facilitate trip bookings. Using Azure Cosmos DB for this purpose helps ensure speed, scale, and simplicity, as described [earlier](#building-a-robust-memory-system-for-ai-agents).
213+
The AI travel agent's [unified memory system](#characteristics-of-a-robust-ai-agent-memory-system) uses the [vector database](vector-database.md) and document store capabilities of Azure Cosmos DB to address traveler inquiries and facilitate trip bookings. Using Azure Cosmos DB for this purpose helps ensure speed, scale, and simplicity, as described [earlier](#building-a-robust-ai-agent-memory-system).
216214

217215
The sample agent operates within a Python FastAPI back end. It supports user interactions through a React JavaScript user interface.
218216

219217
### Prerequisites
220218

221219
- An Azure subscription. If you don't have one, you can [try Azure Cosmos DB for free](try-free.md) for 30 days without creating an Azure account. The free trial doesn't require a credit card, and no commitment follows the trial period.
222220
- An account for the OpenAI API or Azure OpenAI Service.
223-
- A vCore cluster in Azure Cosmos DB for MongoDB. You can create one by following [this QuickStart](mongodb/vcore/quickstart-portal.md).
221+
- A vCore cluster in Azure Cosmos DB for MongoDB. You can create one by following [this quickstart](mongodb/vcore/quickstart-portal.md).
224222
- An integrated development environment, such as Visual Studio Code.
225223
- Python 3.11.4 installed in the development environment.
226224

@@ -230,7 +228,7 @@ All of the code and sample datasets are available in [this GitHub repository](ht
230228

231229
- *loader*: This folder contains Python code for loading sample documents and vector embeddings in Azure Cosmos DB.
232230
- *api*: This folder contains the Python FastAPI project for hosting the AI travel agent.
233-
- *web*: The folder contains the web interface with React JavaScript.
231+
- *web*: This folder contains code for the React web interface.
234232

235233
### Load travel documents into Azure Cosmos DB
236234

@@ -350,7 +348,7 @@ Create a file named *.env* in the *api* directory, to store your environment var
350348
MONGO_CONNECTION_STRING="mongodb+srv:<your connection string from Azure Cosmos DB>"
351349
```
352350

353-
Now that the environment is configured and variables are set up, run the following command from the *api* directory to initiate the server:
351+
Now that you've configured the environment and set up variables, run the following command from the *api* directory to initiate the server:
354352

355353
```python
356354
python app.py
@@ -374,7 +372,7 @@ Select **Try it out** for `/session/`.
374372
}
375373
```
376374

377-
For the AI agent, you only need to simulate a session. The stubbed-out method merely returns a generated session ID for tracking message history. In a practical implementation, this session would be stored in Azure Cosmos DB and potentially in React JavaScript `localStorage`.
375+
For the AI agent, you only need to simulate a session. The stubbed-out method merely returns a generated session ID for tracking message history. In a practical implementation, this session would be stored in Azure Cosmos DB and potentially in React `localStorage`.
378376

379377
Here are the contents of *web/session.py*:
380378

@@ -487,11 +485,11 @@ The *init.py* file initiates the loading of environment variables from an *.env*
487485

488486
The `LLM_init()` method is invoked during module initialization to configure the AI agent for conversation via the API web layer. The OpenAI `chat` object is instantiated through the GPT-3.5 model and incorporates specific parameters such as model name and temperature. The `chat` object, tools list, and prompt template are combined to generate `AgentExecutor`, which operates as the AI travel agent.
489487

490-
The agent with history, `agent_with_chat_history`, is established through `RunnableWithMessageHistory` with chat history (`MongoDBChatMessageHistory`), which enables it to maintain a complete conversation history via Azure Cosmos DB.
488+
The agent with history, `agent_with_chat_history`, is established through `RunnableWithMessageHistory` with chat history (`MongoDBChatMessageHistory`). This action enables it to maintain a complete conversation history via Azure Cosmos DB.
491489

492490
#### Prompt
493491

494-
The LLM prompt initially began with the simple statement "You are a helpful and friendly travel assistant for a cruise company." However, testing showed that you could obtain more consistent results by including the instruction "Answer travel questions to the best of your ability, providing only relevant information. To book a cruise, capturing the person's name is essential." The results appear in HTML format to enhance the visual appeal within the web interface.
492+
The LLM prompt initially began with the simple statement "You are a helpful and friendly travel assistant for a cruise company." However, testing showed that you could obtain more consistent results by including the instruction "Answer travel questions to the best of your ability, providing only relevant information. To book a cruise, capturing the person's name is essential." The results appear in HTML format to enhance the visual appeal of the web interface.
495493

496494
#### Agent tools
497495

@@ -584,11 +582,11 @@ def agent_chat(input:str, session_id:str)->str:
584582

585583
The *TravelAgent.py* file is straightforward, because `agent_with_chat_history` and its dependencies (tools, prompt, and LLM) are initialized and configured in the *init.py* file. This file calls the agent by using the input received from the user, along with the session ID for conversation memory. Afterward, `PromptResponse` (model/prompt) is returned with the agent's output and response time.
586584

587-
## AI agent integration with the React JavaScript user interface
585+
## AI agent integration with the React user interface
588586

589-
With the successful loading of the data and accessibility of the AI agent through the API, you can now complete the solution by establishing a web user interface (by using React JavaScript) for your travel website. Using the capabilities of React JavaScript helps illustrate the seamless integration of the AI agent into a travel site. This integration enhances the user experience with a conversational travel assistant for inquiries and bookings.
587+
With the successful loading of the data and accessibility of the AI agent through the API, you can now complete the solution by establishing a web user interface (by using React) for your travel website. Using the capabilities of React helps illustrate the seamless integration of the AI agent into a travel site. This integration enhances the user experience with a conversational travel assistant for inquiries and bookings.
590588

591-
### Set up the environment for React JavaScript
589+
### Set up the environment for React
592590

593591
Install Node.js and the dependencies before testing the React interface.
594592

@@ -608,11 +606,11 @@ Now, run the following command from the *web* directory to initiate the React we
608606
npm start
609607
```
610608

611-
Running the previous command opens the React JavaScript web application.
609+
Running the previous command opens the React web application.
612610

613611
:::image type="content" source="media/gen-ai/ai-agent/react-js-travel-web-application.png" lightbox="media/gen-ai/ai-agent/react-js-travel-web-application.png" alt-text="Screenshot of the React JavaScript travel web application.":::
614612

615-
### Walk through the React JavaScript web interface
613+
### Walk through the React web interface
616614

617615
The web project of the GitHub repository is a straightforward application to facilitate user interaction with the AI agent. The primary components required to converse with the agent are *TravelAgent.js* and *ChatLayout.js*. The *Main.js* file serves as the central module or user landing page.
618616

@@ -813,7 +811,7 @@ Select **Effortlessly plan your voyage** to open the travel assistant.
813811

814812
#### Chat layout
815813

816-
The chat layout component, as indicated by its name, oversees the arrangement of the chat. It systematically processes the chat messages and implements the formatting specified in the `message` JSON object.
814+
The chat layout component oversees the arrangement of the chat. It systematically processes the chat messages and implements the formatting specified in the `message` JSON object.
817815

818816
Here are the contents of *TripPlanning/ChatLayout.py*:
819817

0 commit comments

Comments
 (0)