StackA2A
data-analyticsOfficialpython

Analytics (Official Sample)

59

by A2A Project

Official A2A python sample agent: Analytics

1,329 starsUpdated 2026-02-22apache-2.0
Quality Score59/100
Community
70
Freshness
100
Official
100
Skills
10
Protocol
30
🔒 Security
20

Getting Started

1Clone the repository
$ git clone https://github.com/a2aproject/a2a-samples
2Navigate to the project
$ cd a2a-samples/samples/python/agents/analytics
3Install dependencies
$ pip install -r requirements.txt
4Run the agent
$ python main.py

README

Analytics Agent with A2A Protocol

This sample demonstrates a lightweight analytics agent that generates charts (bar for now; will be enhanced to handle more chart types) from user prompts using CrewAI, pandas, and matplotlib, and serves them via the A2A Protocol.

YouTube Tutorial

While initially focused on charting, this agent sets the foundation for more advanced analytics workflows.


What It Does

This agent turns simple user prompts (e.g. "Generate a chart of revenue: Jan,$1000 Feb,$2000 Mar,$1500") into visual charts. It uses:

  • Natural language + structured values → parsed to CSV
  • Chart inference → preps data for a bar chart
  • Matplotlib rendering → outputs PNG image
  • CrewAI + A2A → standardized interaction with external clients

Example result:

🧾 Prompt: Generate a chart of revenue: Jan,$1000 Feb,$2000 Mar,$1500
📊 Output: PNG image of a chart


How It Works

The architecture uses CrewAI and optionally the Gemini API (or OpenAI) to interpret prompts and generate visual output. The A2A protocol facilitates communication between the client and the agent.

sequenceDiagram
    participant Client as A2A Client
    participant Server as A2A Server
    participant Agent as CrewAI Agent
    participant Matplotlib as Chart Renderer

    Client->>Server: Send prompt (e.g. "Sales: A:100, B:200")
    Server->>Agent: Forward prompt
    Agent->>Matplotlib: Generate chart image
    Matplotlib-->>Agent: Return PNG
    Agent->>Server: Return image ID
    Server->>Client: Return image artifact

Key Components

  • CrewAI Agent: Image generation agent with specialized tools
  • A2A Server: Provides standardized protocol for interacting with the agent
  • Image Generation: Uses Gemini API to create images from text descriptions
  • Cache System: Stores generated images for retrieval (in-memory or file-based)

Prerequisites

  • Python 3.12 or higher
  • UV package manager (recommended)
  • Google API Key (for Gemini access)

Setup & Running

  1. Navigate to the samples directory:

    cd samples/python/agents/analytics
    
  2. Create an environment file with your API key (or Vertex AI credentials):

    echo "OPENAI_API_KEY=your_openai_key_here" > .env
    
  3. Set up the Python environment:

    uv python pin 3.12
    uv venv
    source .venv/bin/activate
    
  4. Run the agent with desired options:

    # Basic run
    uv run .
    
    # On custom host/port
    uv run . --host 0.0.0.0 --port 8080
    
  5. Run the A2A client:

    In a separate terminal:

    cd samples/python/hosts/cli
    uv run . --agent http://localhost:10011
    

    If you changed the agent's port when starting it, update the URL accordingly:

    uv run . --agent http://localhost:YOUR_PORT
    

    Or run the demo app


Features & Improvements

Features:

  • Text-to-chart-image generation using Google Gemini and Matplotlib
  • Support for OpenAI and Gemini LLMs
  • Robust error handling with automatic retries
  • Optional file-based cache persistence
  • Improved artifact ID extraction from queries
  • Returns PNG images directly to the client
  • A2A protocol compatibility

Limitations:

  • No true streaming (CrewAI doesn't natively support it)
  • Limited agent interactions (no multi-turn conversations)

Learn More


By

Gabe Jakobson, 2025

Disclaimer

Important: The sample code provided is for demonstration purposes and illustrates the mechanics of the Agent-to-Agent (A2A) protocol. When building production applications, it is critical to treat any agent operating outside of your direct control as a potentially untrusted entity.

All data received from an external agent—including but not limited to its AgentCard, messages, artifacts, and task statuses—should be handled as untrusted input. For example, a malicious agent could provide an AgentCard containing crafted data in its fields (e.g., description, name, skills.description). If this data is used without sanitization to construct prompts for a Large Language Model (LLM), it could expose your application to prompt injection attacks. Failure to properly validate and sanitize this data before use can introduce security vulnerabilities into your application.

Developers are responsible for implementing appropriate security measures, such as input validation and secure handling of credentials to protect their systems and users.

Capabilities

StreamingPush NotificationsMulti-TurnAuth: none
official-samplepython

Part of these stacks

View on GitHub