|
| 1 | +#!/usr/bin/env cagent run |
| 2 | + |
| 3 | +metadata: |
| 4 | + readme: | |
| 5 | + This example demonstrates a Tic-Tac-Toe game between two agents, "player_blue" and "player_red", |
| 6 | + organized by a root agent. The root agent manages the game state, enforces the rules, and declares the winner or a draw. |
| 7 | + Each player agent makes moves based on the current state of the board. |
| 8 | +
|
| 9 | + To run the demo: |
| 10 | + cagent a2a --port 8080 ./examples/tic-tac-toe.yaml --agent player_blue |
| 11 | + cagent a2a --port 8081 ./examples/tic-tac-toe.yaml --agent player_red |
| 12 | + cagent run --yolo ./examples/tic-tac-toe.yaml 'Go!' |
| 13 | +
|
| 14 | +agents: |
| 15 | + # Game Organizer |
| 16 | + root: |
| 17 | + model: anthropic/claude-opus-4-5 |
| 18 | + description: A Tic-Tac-Toe game organizer |
| 19 | + instruction: | |
| 20 | + <identity> |
| 21 | + You are a Tic-Tac-Toe game organizer. Your goal is to make your two subagents play Tic-Tac-Toe against each other. |
| 22 | + You keep track of the game state, enforce the rules, and declare the winner or a draw at the end of the game. |
| 23 | + You communicate with your two subagents, "player_blue" and "player_red", to get their moves and update the game board accordingly. |
| 24 | + </identity> |
| 25 | +
|
| 26 | + <game> |
| 27 | + On each player's first turn, you inform them of their assigned mark: "X" for player_blue and "O" for player_red. |
| 28 | + </game> |
| 29 | +
|
| 30 | + <preparation> |
| 31 | + Before the game, you must prepare an html page that visually represents the Tic-Tac-Toe board. |
| 32 | + - Make it retro and super flashy! |
| 33 | + - Serve this page on a local web server that you runs as a background job. (Stop it at the end of the game.) |
| 34 | + - Always work in /tmp |
| 35 | + - IMPORTANT: Make sure you can ping the page before starting the game. We don't want users to miss the game! |
| 36 | + - The page shows the user the current state of the board and is updated live with javascript and live-reload. |
| 37 | + - On each turn, you update the page to reflect the current state of the board. It MUST auto-refresh with you update the state/ |
| 38 | + - IMPORTANT: You must open a browser on this URL before the players start to play, for the user to follow the game. |
| 39 | + - (The url can't be on port 8080 or 8081, as those are used by the players' agents.) |
| 40 | + </preparation> |
| 41 | + add_environment_info: true |
| 42 | + toolsets: |
| 43 | + - type: shell |
| 44 | + - type: filesystem |
| 45 | + - type: a2a |
| 46 | + name: player_blue |
| 47 | + url: http://localhost:8080/ |
| 48 | + - type: a2a |
| 49 | + name: player_red |
| 50 | + url: http://localhost:8081/ |
| 51 | + |
| 52 | + # BLUE Player |
| 53 | + player_blue: |
| 54 | + model: openai/gpt-4.1-nano |
| 55 | + description: A Tic-Tac-Toe player |
| 56 | + instruction: | |
| 57 | + You know how to play Tic-Tac-Toe. You will be playing against another agent in a game organized by a third agent. |
| 58 | + When it's your turn, you will receive the current state of the board and you need to choose your move by specifying |
| 59 | + the row and column (0-indexed) where you want to place your mark (X or O). |
| 60 | +
|
| 61 | + # RED Player |
| 62 | + player_red: |
| 63 | + model: anthropic/claude-haiku-4-5 |
| 64 | + description: A Tic-Tac-Toe player |
| 65 | + instruction: | |
| 66 | + You know how to play Tic-Tac-Toe. You will be playing against another agent in a game organized by a third agent. |
| 67 | + When it's your turn, you will receive the current state of the board and you need to choose your move by specifying |
| 68 | + the row and column (0-indexed) where you want to place your mark (X or O). |
0 commit comments