You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample demonstrates how to use `DynamicAgentRequestHandler` to create a server that can dynamically route to different agents based on the URL path.
4
+
5
+
The server provides two working example agents:
6
+
-**Calculator Agent**: Performs basic math operations like "2 + 2" or "10 * 5"
7
+
-**Weather Agent**: Provides fake weather data for major cities (London, Paris, Tokyo, New York, Sydney)
The `DynamicAgentRequestHandler` inspects the incoming URL and dynamically determines:
27
+
1. Which agent card to return
28
+
2. Which task store to use
29
+
3. Which agent executor to run
30
+
31
+
This allows a single route setup (`/agents`) to handle multiple different agent behaviors without needing separate route configurations for each agent.
32
+
33
+
## Testing the Agents
34
+
35
+
### Using the CLI Client
36
+
37
+
The easiest way to test the agents is using the built-in CLI client:
38
+
39
+
```bash
40
+
# Test the calculator agent
41
+
npm run sample:cli -- http://localhost:3000/agents/calculator/
42
+
# Try typing: 1 + 1
43
+
44
+
# Test the weather agent
45
+
npm run sample:cli -- http://localhost:3000/agents/weather/
46
+
# Try typing: whats weather in tokyo
47
+
```
48
+
49
+
### Using curl or HTTP clients
50
+
51
+
You can also test the agents using curl or any HTTP client:
result=`The weather in ${foundCity.charAt(0).toUpperCase()+foundCity.slice(1)} is currently ${temp}°C and ${conditions}. (This is fake data for demonstration purposes!)`;
119
+
}else{
120
+
result="I can provide weather information! Try asking about the weather in London, Paris, Tokyo, New York, or Sydney.";
This sample demonstrates how to create an A2A agent server that requires authorization via a special Authorization header. The agent will only respond to requests that include the correct Bearer token.
4
+
5
+
## Features
6
+
7
+
-**Authorization Required**: All requests must include a valid `Authorization: Bearer <token>` header
8
+
-**Security**: Returns 401 for missing auth headers and 403 for invalid tokens
9
+
-**Custom Request Handler**: Extends the default request handler to add authentication middleware
10
+
-**Clear Error Messages**: Provides helpful error responses for unauthorized requests
The sample creates a custom `AuthorizedRequestHandler` that extends the default `DefaultRequestHandler` and overrides the `handleRequest` method to check for proper authorization before allowing access to the agent.
72
+
73
+
The required token is: `secret-auth-token-12345`
74
+
75
+
## Security Notes
76
+
77
+
- In production, use proper JWT tokens or OAuth2 flows
78
+
- Store secrets securely (environment variables, secret managers)
79
+
- Consider rate limiting and other security measures
0 commit comments