Content
# A2A Sample Implementation
This project is a sample implementation of Agent-to-Agent (A2A). It implements a recipe suggestion agent and operates as a server using the A2A SDK.
## Project Structure
```
a2a-sample/
├── src/
│ ├── client/ # Client-side implementation
│ │ ├── index.ts # Main entry point for the client
│ │ └── config/ # Client configuration
│ ├── server/ # Server-side implementation
│ │ ├── index.ts # Main entry point for the server
│ │ ├── recipe_agent.ts # Implementation of the recipe suggestion agent
│ │ ├── config/ # Server configuration
│ │ └── mastra/ # Implementation related to Mastra
│ └── cli.ts # Implementation of the CLI for the terminal
├── assets/ # Static assets
├── package.json # Project configuration and dependencies
├── tsconfig.json # TypeScript configuration
└── .env # Environment variable configuration
```
## Features
### Server Side
- Recipe Suggestion Agent
- Suggests recipes based on user requests
- Retrieves recipe information through web searches
- Provides detailed information about recipes
### Client Side
- Slack Client
## How to Run
### Prerequisites
- Node.js (v18 or higher)
- npm
### Setup
1. Clone the repository
```bash
git clone [repository-url]
cd a2a-sample
```
2. Install dependencies
```bash
npm install
```
3. Set up environment variables
Create a `.env` file and configure the necessary environment variables.
### Running in Development Environment
1. Start the server (run in a separate terminal)
```bash
npm run dev:server
```
2. Start the Slack client
```bash
npm run dev:client
```
### Running the CLI
You can also connect via the CLI.
```bash
npx ts-node src/cli.ts
```
```
A2A Terminal Client
Agent URL: http://localhost:41241
Attempting to fetch agent card from: http://localhost:41241/.well-known/agent.json
✓ Agent Card Found:
Name: Recipe Agent
Description: An agent that suggests cooking recipes based on natural language instructions
Version: 0.0.1
Starting Task ID: 438ccc1b-51e2-44b1-929c-769ca331f190
Enter messages, or use '/new' to start a new task.
Recipe Agent > You: カレー
Sending...
Recipe Agent [5:32:37 PM]: ⏳ Status: working
Part 1: 📝 Text: Searching for recipes...
Recipe Agent [5:32:38 PM]: 🤔 Status: input-required
Part 1: 📝 Text: Please choose a dish from the following options: Chicken Curry, Vegetable Curry, Beef Curry, Seafood Curry, Keema Curry
SSE stream finished for method tasks/sendSubscribe.
--- End of response for this input ---
Recipe Agent > You: チキンカレー
Sending...
Recipe Agent [5:33:11 PM]: ⏳ Status: working
Part 1: 📝 Text: Searching for recipes...
Recipe Agent [5:33:17 PM]: ✅ Status: completed
Part 1: 📝 Text: 【Chicken Curry】
【Ingredients】(for 2 servings)
- 300g chicken thigh
- 1 onion
- 1 clove garlic
- 1 piece ginger
- 2 tablespoons curry powder
- 1 can of tomatoes
- 200ml coconut milk
- Salt to taste
- 1 tablespoon salad oil
- Coriander (optional)
【Instructions】
1. Cut the chicken thigh into bite-sized pieces and season with salt.
2. Finely chop the onion, garlic, and ginger.
3. Heat salad oil in a frying pan, sauté the onion until translucent.
4. Add garlic and ginger, and sauté until fragrant.
5. Add the chicken and sauté until the surface turns white.
6. Add curry powder and mix well.
7. Add the can of tomatoes and coconut milk, and bring to a boil.
8. Simmer for about 15 minutes over medium heat, adjusting the taste with salt.
9. Garnish with coriander if desired.
【Tips】
- Sautéing the chicken thoroughly brings out its flavor.
- Adding coconut milk gives a creamy taste.
SSE stream finished for method tasks/sendSubscribe.
--- End of response for this input ---
```