Chapters: 

# One Sentence Summary

The system combines **LLM reasoning, guardrails, tools, and a vector database** into a coordinated workflow managed by the **OpenAI Agents SDK Runner**.

๐Ÿฅ Only ask questions about food

AI Agents in a Nutshell โ€” Architecture

User
  |
  v
Chainlit
(UI + Authentication + Chat Interface)
  |
  v
OpenAI Agents SDK
Runner
(Orchestration Layer)
  |
  +------------------------+
  |                        |
  v                        v
Input Guardrail            Agent
(topic filter)             (LLM reasoning)
  |                        |
  |                        v
  |                      Tools
  |                  (calorie_lookup_tool)
  |                        |
  +------------------------+
                           |
                           v
                        ChromaDB
                    (Vector Database)
                 nutrition_db collection
                           |
                           v
                  Post-Processing Hook
                    (Croissant Upsell)
                           |
                           v
                     Final Response

### Chainlit

Provides the **chat interface and authentication**.

Handles:

* message streaming
* UI steps for tool calls
* user login

---

### OpenAI Agents SDK

The **Runner** orchestrates everything:

* calls the agent
* enforces guardrails
* executes tools
* streams results back

---

### Agent

The AI reasoning layer.

It decides:

```
answer directly
OR
call a tool
```

---

### Guardrails

Input guardrails ensure the system only answers **nutrition-related questions**.

Example blocked question:

```
How many roads lead to Rome?
```

---

### Tools

Custom functions the agent can call.

Example:

```
calorie_lookup_tool()
```

Which queries the vector database.

---

### ChromaDB

Stores food data as **vector embeddings**.

Example:

```
Peanut Butter โ†’ 384-dimensional vector
```

Semantic search finds foods based on meaning rather than keywords.

---

### Post-Processing Hook

After the model finishes, a custom function modifies the response.

Example feature:

```
๐Ÿฅ Croissant upsell for French cuisine
```


def croissant_upsell(text: str) -> str:
    french_triggers = [
        "france",
        "french",
        "paris",
        "niรงoise",
        "provence",
        "dijon",
        "bordeaux",
        "baguette",
    ]

    if any(word in text.lower() for word in french_triggers):
        text += "\n\n๐Ÿฅ For only 120 calories more, may we interest you in a croissant with that?"

    return text

---

https://ai-agents-in-a-nutshell.onrender.com/

---

# Why This Architecture Matters

It demonstrates how modern AI applications are built:

```
LLM
+ tools
+ retrieval
+ orchestration
+ deployment
```

The model provides reasoning, but the **framework coordinates the system**.

---

AI Agents in a Nutshell โ€” Architecture

+----------------------+
|         User         |                
|   Browser / Tester   |
+----------+-----------+
           |
           v
+----------------------+
|      Chainlit        |
|  UI + Auth + Chat    |
+----------+-----------+
           |
           v
+----------------------+
| OpenAI Agents SDK    |
|       Runner         |
|   Orchestration      |
+----------+-----------+
           |
     +-----+-----+
     |           |
     v           v
+---------+   +------------------+
| Input   |   |      Agent       |
| Guardrail|  |   LLM Reasoning  |
+----+----+   +---------+--------+
     |                    |
     |                    v
     |              +------------+
     |              |   Tools    |
     |              | calorie    |
     |              | lookup     |
     |              +------+-----+
     |                     |
     +---------------------+
                           |
                           v
                  +------------------+
                  |     ChromaDB     |
                  |  nutrition_db    |
                  |  vector search   |
                  +--------+---------+
                           |
                           v
                  +------------------+
                  | Post-Processing  |
                  | Croissant Upsell |
                  +--------+---------+
                           |
                           v
                  +------------------+
                  |  Final Response  |
                  +------------------+
 

๐Ÿฅ Only answers question about food. Some questions about French food will try to upsell you a croissant. That is the bonus "Output Guardrail".ย 

ย 

ย 

ย