This project demonstrates an Agent-to-Agent (A2A) conversation using LangGraph with the A2A protocol in TypeScript.
-
Install dependencies:
cd typescript npm install -
Configure environment variables:
cp .env.example .env
Edit
.envand add yourOPENAI_API_KEY.
-
Start the first agent server:
npx @langchain/langgraph-cli dev --port 2024
Copy the
assistant_idfrom the output. -
In another terminal, start the second agent server:
npx @langchain/langgraph-cli dev --port 2025
Copy the
assistant_idfrom this output as well.Access API Documentation:
- LangGraph Studio: The server output will show a Studio UI link (e.g.,
https://smith.langchain.com/studio?baseUrl=http://localhost:2025). This is the primary way to view API documentation, test endpoints, and visualize your graph in the TypeScript version. - Note: The TypeScript LangGraph dev server does not expose a
/docsendpoint like the Python version. Use LangGraph Studio for API exploration.
- LangGraph Studio: The server output will show a Studio UI link (e.g.,
-
Configure the assistant IDs: Add the following to your
.envfile:AGENT_A_ID=<assistant_id_from_port_2024> AGENT_B_ID=<assistant_id_from_port_2025> -
Run the conversation simulation:
npm run conversation
This will simulate a conversation between the two agents, with each agent responding to the other's messages.
The implementation consists of two main components:
1. LangGraph Agent (src/langgraph_agent.ts)
- Defines a conversational agent using LangGraph's StateGraph
- Uses OpenAI's GPT-4o-mini for responses
- Maintains message history in state
- Configured for brief, engaging responses (max 100 tokens)
2. A2A Conversation Orchestrator (src/a2a_conversation.ts)
- Sends messages between two agent instances using the A2A protocol
- Uses JSON-RPC 2.0 format for agent communication
- Orchestrates 3 rounds of back-and-forth conversation
- Displays conversation with colored output for each agent
typescript/
├── src/
│ ├── langgraph_agent.ts # Agent definition and logic
│ └── a2a_conversation.ts # Conversation orchestrator
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment template
└── README.md # This file
npm run dev- Watch mode for developmentnpm run build- Build TypeScript to JavaScriptnpm run conversation- Run the A2A conversation simulation
- Each agent runs as a separate LangGraph server on different ports (2024 and 2025)
- Both agents use the same logic (GPT-4o-mini) but maintain independent state
- The A2A protocol enables standardized communication between agents
- Responses are kept brief (100 token limit) for concise conversations