|
1 | 1 | # Step 2: Getting Started with cagent |
2 | 2 |
|
3 | | -## First, let's set up your API keys |
| 3 | +## Install cagent |
4 | 4 |
|
5 | | -To use cagent, you'll need at least one API key from your preferred AI provider. Please provide the API key(s) you want to use: |
| 5 | +1. Run the following commands to install cagent into your lab environment: |
6 | 6 |
|
7 | | -::variableDefinition[openaikey]{prompt="Enter your OpenAI API key (or leave blank if not using OpenAI)"} |
| 7 | + ```bash |
| 8 | + # Download the latest cagent Linux binary |
| 9 | + curl -L -o /tmp/cagent https://github.com/docker/cagent/releases/latest/download/cagent-linux-amd64 |
8 | 10 |
|
9 | | -::variableDefinition[anthropickey]{prompt="Enter your Anthropic API key (or leave blank if not using Anthropic)"} |
| 11 | + # Make it executable |
| 12 | + chmod +x /tmp/cagent |
10 | 13 |
|
11 | | -::variableDefinition[googlekey]{prompt="Enter your Google/Gemini API key (or leave blank if not using Google)"} |
| 14 | + # Move it to a location in your PATH |
| 15 | + sudo mv /tmp/cagent /usr/local/bin/cagent |
| 16 | + ``` |
12 | 17 |
|
13 | | -## Setting Up Your Environment |
| 18 | +2. Once the install is completed, verify it by checking the version information: |
14 | 19 |
|
15 | | -Now that you've provided your API key(s), let's set them in your environment. Copy and run the following commands in the terminal based on the provider(s) you're using: |
| 20 | + ```bash |
| 21 | + cagent version |
| 22 | + ``` |
16 | 23 |
|
17 | | -```bash |
18 | | -# For OpenAI models (if you provided an OpenAI key) |
19 | | -export OPENAI_API_KEY=$$openaikey$$ |
| 24 | + You should see output showing the cagent version. |
20 | 25 |
|
21 | | -# For Anthropic models (if you provided an Anthropic key) |
22 | | -export ANTHROPIC_API_KEY=$$anthropickey$$ |
23 | 26 |
|
24 | | -# For Gemini models (if you provided a Google key) |
25 | | -export GOOGLE_API_KEY=$$googlekey$$ |
26 | | -``` |
| 27 | +## API setup |
| 28 | + |
| 29 | +In order to complete this lab, you will need an API key from one of the following providers: |
| 30 | + |
| 31 | +::variableSetButton[Use OpenAI]{variables="provider=openai,model=openai/gpt-5-nano,modelShort=gpt-5-nano"} |
| 32 | + |
| 33 | +::variableSetButton[Use Anthropic]{variables="provider=anthropic,model=anthropic/claude-sonnet-4-6,modelShort=claude-sonnet-4-6"} |
27 | 34 |
|
28 | | -> **Note:** You only need to set the API keys for the providers you plan to use. At minimum, you need one valid API key to proceed. |
| 35 | +::variableSetButton[Use Gemini]{variables="provider=gemini,model=google/gemini-2.5-flash,modelShort=gemini-2.5-flash"} |
29 | 36 |
|
30 | | -## Your First Agent |
| 37 | + |
31 | 38 |
|
32 | | -Let's create the simplest possible agent. Run this command in the terminal to create `basic_hello.yaml`: |
| 39 | +:::conditionalDisplay{variable="provider" requiredValue="openai"} |
| 40 | +### OpenAI configuration |
| 41 | + |
| 42 | +::variableDefinition[openaikey]{prompt="Enter your OpenAI API key (or leave blank if not using OpenAI)"} |
33 | 43 |
|
34 | 44 | ```bash |
35 | | -cat > basic_hello.yaml << 'EOF' |
36 | | -agents: |
37 | | - root: |
38 | | - model: openai/gpt-4o |
39 | | - instruction: You talk like a pirate |
40 | | -EOF |
| 45 | +export OPENAI_API_KEY=$$openaikey$$ |
41 | 46 | ``` |
| 47 | +::: |
42 | 48 |
|
43 | | -Now let's run this amazing agent: |
| 49 | + |
| 50 | +:::conditionalDisplay{variable="provider" requiredValue="anthropic"} |
| 51 | +### Anthropic configuration |
| 52 | + |
| 53 | +::variableDefinition[anthropickey]{prompt="Enter your Anthropic API key (or leave blank if not using Anthropic)"} |
44 | 54 |
|
45 | 55 | ```bash |
46 | | -cagent run basic_hello.yaml |
| 56 | +# For Anthropic models (if you provided an Anthropic key) |
| 57 | +export ANTHROPIC_API_KEY=$$anthropickey$$ |
47 | 58 | ``` |
| 59 | +::: |
48 | 60 |
|
49 | | -If everything is setup correctly, you should see the TUI and be able to ask a |
50 | | -question to your agent and it should answer in pirate speak. |
51 | 61 |
|
| 62 | +:::conditionalDisplay{variable="provider" requiredValue="gemini"} |
| 63 | +### Gemini configuration |
52 | 64 |
|
| 65 | +::variableDefinition[googlekey]{prompt="Enter your Google/Gemini API key (or leave blank if not using Google)"} |
53 | 66 |
|
54 | | -To exit the TUI, press `Ctrl+C`. |
| 67 | +```bash |
| 68 | +export GOOGLE_API_KEY=$$googlekey$$ |
| 69 | +``` |
| 70 | +::: |
55 | 71 |
|
56 | | -## Choosing Different Models |
57 | 72 |
|
58 | | -If you don't have access to OpenAI, or want to use a different provider, you can easily swap the model in your YAML configuration. Visit [models.dev](https://models.dev) and look for models that exist for your provider. |
| 73 | +## Writing your First Agent |
59 | 74 |
|
60 | | -`cagent` supports these providers: |
| 75 | +Let's create the simplest possible agent. |
61 | 76 |
|
62 | | -- **`openai`** - OpenAI models (GPT-4, GPT-4o, etc.) |
63 | | -- **`anthropic`** - Anthropic models (Claude 3.5 Sonnet, etc.) |
64 | | -- **`google`** - Google Gemini models |
65 | | -- **`dmr`** - Use any local [Docker Model Runner](https://docs.docker.com/ai/model-runner/) model that you already have pulled locally |
| 77 | +1. Create a file named `basic_hello.yaml` with the following contents: |
66 | 78 |
|
67 | | -For example, to use Anthropic's Claude instead, create a new file: |
| 79 | + ```yaml save-as=basic_hello.yaml |
| 80 | + agents: |
| 81 | + root: |
| 82 | + model: $$model$$ |
| 83 | + instruction: You talk like a pirate |
| 84 | + ``` |
68 | 85 |
|
69 | | -```bash |
70 | | -cat > basic_hello_claude.yaml << 'EOF' |
71 | | -agents: |
72 | | - root: |
73 | | - model: anthropic/claude-3-5-sonnet-20241022 |
74 | | - instruction: You talk like a pirate |
75 | | -EOF |
76 | | -``` |
| 86 | +2. Run this amazing agent using the following command: |
77 | 87 |
|
78 | | -Then run it: |
| 88 | + ```bash |
| 89 | + cagent run basic_hello.yaml |
| 90 | + ``` |
79 | 91 |
|
80 | | -```bash |
81 | | -cagent run basic_hello_claude.yaml |
82 | | -``` |
| 92 | +3. Ask your agent a simple question to see it answer in pirate speak: |
| 93 | +
|
| 94 | + ```console |
| 95 | + Give me an interesting and lesser-known fact about Docker |
| 96 | + ``` |
| 97 | +
|
| 98 | +4. To exit the agent's interface, press `Ctrl+C`. |
83 | 99 |
|
84 | 100 |
|
85 | 101 | ## Next Steps |
|
0 commit comments