|
1 | | -# Contoso Burgers AI lightweight Agent CLI |
| 1 | +<div align="center"> |
2 | 2 |
|
3 | | -## Available Scripts |
| 3 | +# Agent CLI (LangChain.js) |
4 | 4 |
|
5 | | -In the project directory, you can run: |
| 5 | + |
| 6 | +[](https://www.typescriptlang.org) |
| 7 | +[](https://js.langchain.com) |
6 | 8 |
|
7 | | -### `npm start` |
| 9 | +[Overview](#overview) • [Usage](#usage) • [Development](#development) • [Troubleshooting](#troubleshooting) |
8 | 10 |
|
9 | | -Run the burger agent CLI. Usage examples: |
| 11 | +</div> |
10 | 12 |
|
11 | | -```bash |
12 | | -# Ask a simple question |
13 | | -npm run start "show me the burger menu" |
| 13 | +## Overview |
14 | 14 |
|
15 | | -# Ask with a specific user ID |
16 | | -npm run start "place an order" -- --userId user123 |
| 15 | +The Agent CLI is a minimal command line interface to the same burger ordering LangChain.js agent used by the web experience. It connects directly to the Burger MCP server and uses Azure OpenAI for reasoning. Conversation state is persisted locally in a JSON file so you can build context across multiple invocations. |
17 | 16 |
|
18 | | -# Start a new session |
19 | | -npm run start "hello" -- --new |
| 17 | +It is useful for: |
20 | 18 |
|
21 | | -# Use local MCP server |
22 | | -npm run start "show me the menu" -- --local |
| 19 | +- Rapid prototyping / debugging tool calls |
| 20 | +- Local experimentation without the web UI |
| 21 | +- Understanding LangChain.js agent setup in a simplified context |
23 | 22 |
|
24 | | -# Combine options |
25 | | -npm run start "cancel my order" -- --userId user123 --new --local |
26 | | -``` |
| 23 | +<div align="center"> |
| 24 | + <img src="../../docs/images/cli-architecture.drawio.png" alt="Architecture" /> |
| 25 | +</div> |
27 | 26 |
|
28 | | -The CLI maintains conversation history in `~/.burger-agent-cli/burger-agent-cli.json` for context across sessions. |
| 27 | +## Installation |
29 | 28 |
|
30 | | -### Options |
| 29 | +Follow the instructions [here](../../README.md#getting-started) to set up the development environment for the entire Burger MCP Agents project. |
| 30 | + |
| 31 | +Then run the following commands from the repository root: |
31 | 32 |
|
32 | | -- `--userId <userId>`: Specify a user ID for operations that require user context (like placing or cancelling orders) |
33 | | -- `--new`: Start a new conversation session, discarding previous history |
34 | | -- `--verbose`: Show intermediate steps and tool calls during execution |
35 | | -- `--local`: Force connection to localhost MCP server (http://localhost:3000/mcp) instead of using BURGER_MCP_URL environment variable |
| 33 | +```bash |
| 34 | +cd packages/agent-cli |
| 35 | +npm start "show me a spicy burger" |
| 36 | +``` |
36 | 37 |
|
37 | | -### `npm run build` |
| 38 | +You should see a connection message to the Burger MCP server then the streamed assistant answer. |
38 | 39 |
|
39 | | -To build the CLI for production to the `dist` folder. |
| 40 | +### Global CLI install (optional) |
40 | 41 |
|
41 | | -After building, you can install the CLI globally with: |
| 42 | +You can build and install the CLI globally to call it directly as `agent-cli`: |
42 | 43 |
|
43 | 44 | ```bash |
| 45 | +npm run build |
44 | 46 | npm install -g . |
| 47 | +agent-cli "show me a spicy burger" |
45 | 48 | ``` |
46 | 49 |
|
47 | | -And then run it with: |
| 50 | +## Usage |
| 51 | + |
| 52 | +Invoke with a natural language question or instruction about burgers or orders. The agent will refuse unrelated topics. |
48 | 53 |
|
49 | 54 | ```bash |
50 | | -agent-cli --help |
| 55 | +# Basic menu query |
| 56 | +npm start "show me the burger menu" |
| 57 | + |
| 58 | +# Place an order (will ask for userId if missing) |
| 59 | +npm start "place an order for 2 classic burgers" |
| 60 | + |
| 61 | +# Provide user id explicitly |
| 62 | +npm start "place an order for 1 veggie burger" -- --userId user123 |
| 63 | + |
| 64 | +# Cancel an order (new clean session) |
| 65 | +npm start "cancel order 42" -- --userId user123 --new |
| 66 | + |
| 67 | +# Force local MCP endpoint (bypass BURGER_MCP_URL) |
| 68 | +npm start "what toppings are available" -- --local |
| 69 | + |
| 70 | +# Verbose mode shows intermediate tool steps |
| 71 | +npm start "status of my recent orders" -- --userId user123 --verbose |
| 72 | +``` |
| 73 | + |
| 74 | +> [!TIP] |
| 75 | +> If you installed the CLI globally you can replace `npm start` with `agent-cli` and omit the `--` before options. |
| 76 | +
|
| 77 | +### Options |
| 78 | + |
| 79 | +| Flag | Description | |
| 80 | +|------|-------------| |
| 81 | +| `--userId <id>` | Specify the user identity (required for placing or cancelling orders) | |
| 82 | +| `--new` | Start a fresh session (ignores prior conversation) | |
| 83 | +| `--verbose` | Print intermediate LLM + tool invocation steps | |
| 84 | +| `--local` | Force `http://localhost:3000/mcp` instead of `BURGER_MCP_URL` | |
| 85 | +| `--help` | Display usage information | |
| 86 | + |
| 87 | +### Conversation history |
| 88 | + |
| 89 | +Session data (messages + last used userId) is stored at: |
| 90 | + |
51 | 91 | ``` |
| 92 | +~/.burger-agent-cli/burger-agent-cli.json |
| 93 | +``` |
| 94 | + |
| 95 | +Delete that file or use `--new` to reset context. |
| 96 | + |
| 97 | +### Environment Variables |
| 98 | + |
| 99 | +| Variable | Required | Purpose | Default | |
| 100 | +|----------|----------|---------|---------| |
| 101 | +| `AZURE_OPENAI_API_ENDPOINT` | Yes | Azure OpenAI endpoint used for chat completions | – | |
| 102 | +| `AZURE_OPENAI_MODEL` | No | Model name for the LLM | `gpt-5-mini` | |
| 103 | +| `BURGER_MCP_URL` | No* | Streamable HTTP MCP endpoint | `http://localhost:3000/mcp` | |
| 104 | +| `AGENT_WEBAPP_URL` | No | Used in prompt to guide users where to retrieve their user ID | `http://localhost:4280` | |
| 105 | + |
| 106 | +<sup>*</sup>When not set the CLI falls back to the local development endpoint. Set this when targeting a deployed MCP server. |
| 107 | + |
| 108 | +Authentication to Azure OpenAI uses `DefaultAzureCredential`. Ensure you are logged in by running either `azd auth login` or `az login`. |
| 109 | + |
| 110 | +## Development |
| 111 | + |
| 112 | +### Available Scripts |
| 113 | + |
| 114 | +| Script | Description | |
| 115 | +|--------|-------------| |
| 116 | +| `npm start` | Build then run a single agent interaction | |
| 117 | +| `npm run build` | Compile TypeScript to `dist` | |
| 118 | +| `npm run watch` | Incremental compile in watch mode | |
| 119 | +| `npm run clean` | Remove build artifacts | |
| 120 | + |
| 121 | +## Troubleshooting |
| 122 | + |
| 123 | +- Missing `AZURE_OPENAI_API_ENDPOINT`: set it in the root `.env` or export it in your shell |
| 124 | +- Repeated auth failures: re-run `az login` or clear cached Azure credential tokens |
| 125 | +- MCP connection issues: ensure the MCP server is running and `BURGER_MCP_URL` is correct |
| 126 | + |
0 commit comments