|
1 | 1 | = mongodb-ai-planning-pattern |
| 2 | + |
| 3 | +A Java example demonstrating the Planning Pattern with AI, MongoDB, Jakarta EE, and tool calling through a travel itinerary assistant. |
| 4 | + |
| 5 | +The application showcases how Large Language Models (LLMs) can interact with enterprise systems using tools rather than relying exclusively on model knowledge. Instead of generating answers from training data alone, the AI plans a sequence of actions, invokes tools to retrieve information from MongoDB, and then produces recommendations based on real data. |
| 6 | + |
| 7 | +The sample uses a travel assistant domain where users can explore cities, discover attractions, and generate travel itineraries. The AI agent interacts with the application through tool calling, demonstrating how deterministic software and AI capabilities can work together. |
| 8 | + |
| 9 | +== Architecture |
| 10 | + |
| 11 | +The application combines a traditional Jakarta EE architecture with AI planning capabilities. The user interacts through a JSF and PrimeFaces interface, while LangChain4j orchestrates the AI workflow. Rather than directly accessing MongoDB, the model uses tools that expose application capabilities. These tools delegate to services and repositories, ensuring the AI remains isolated from implementation details and only operates through well-defined actions. |
| 12 | + |
| 13 | +[source,mermaid] |
| 14 | +---- |
| 15 | +graph LR |
| 16 | +subgraph UI["User Interface"] |
| 17 | +JSF["JSF + PrimeFaces"] |
| 18 | +end |
| 19 | +
|
| 20 | +subgraph AI["AI Layer"] |
| 21 | +Agent["TravelService"] |
| 22 | +Planner["Planning Pattern"] |
| 23 | +end |
| 24 | +
|
| 25 | +subgraph Tools["Tool Layer"] |
| 26 | +CityTools["CityTools"] |
| 27 | +AttractionTools["AttractionTools"] |
| 28 | +end |
| 29 | +
|
| 30 | +subgraph Services["Application Layer"] |
| 31 | +CityService["CityService"] |
| 32 | +AttractionService["AttractionService"] |
| 33 | +end |
| 34 | +
|
| 35 | +subgraph Data["Data Layer"] |
| 36 | +CityRepository["CityRepository"] |
| 37 | +AttractionRepository["AttractionRepository"] |
| 38 | +MongoDB[("MongoDB")] |
| 39 | +end |
| 40 | +
|
| 41 | +JSF -->|"User Prompt"| Agent |
| 42 | +Agent --> Planner |
| 43 | +
|
| 44 | +Planner -->|"Uses"| CityTools |
| 45 | +Planner -->|"Uses"| AttractionTools |
| 46 | +
|
| 47 | +CityTools --> CityService |
| 48 | +AttractionTools --> AttractionService |
| 49 | +
|
| 50 | +CityService --> CityRepository |
| 51 | +AttractionService --> AttractionRepository |
| 52 | +
|
| 53 | +CityRepository --> MongoDB |
| 54 | +AttractionRepository --> MongoDB |
| 55 | +
|
| 56 | +style JSF fill:#F8F7F7,stroke:#1D5183,stroke-width:2px,color:#1D5183 |
| 57 | +style Agent fill:#1D5183,stroke:#019DDC,stroke-width:2px,color:#F8F7F7 |
| 58 | +style Planner fill:#F8F7F7,stroke:#019DDC,stroke-width:2px,color:#1D5183 |
| 59 | +style CityTools fill:#F8F7F7,stroke:#1D5183,stroke-width:2px,color:#1D5183 |
| 60 | +style AttractionTools fill:#F8F7F7,stroke:#1D5183,stroke-width:2px,color:#1D5183 |
| 61 | +style CityService fill:#F8F7F7,stroke:#019DDC,stroke-width:2px,color:#1D5183 |
| 62 | +style AttractionService fill:#F8F7F7,stroke:#019DDC,stroke-width:2px,color:#1D5183 |
| 63 | +style CityRepository fill:#F8F7F7,stroke:#019DDC,stroke-width:2px,color:#1D5183 |
| 64 | +style AttractionRepository fill:#F8F7F7,stroke:#019DDC,stroke-width:2px,color:#1D5183 |
| 65 | +style MongoDB fill:#1D5183,stroke:#019DDC,stroke-width:2px,color:#F8F7F7 |
| 66 | +---- |
0 commit comments