Skip to main content
This example demonstrates how to create and use an Upsonic Agent powered by Groq’s ultra-fast inference to perform comprehensive code reviews. The example showcases structured output with Pydantic schemas, web search integration for best practices, and Groq’s speed advantages for developer productivity.

Overview

Upsonic framework provides seamless integration with Groq models. This example showcases:
  1. Groq Integration β€” Using Groq’s fast LLaMA models for code analysis
  2. Structured Output β€” Pydantic schemas for typed, validated responses
  3. Web Search β€” DuckDuckGo integration for current best practices
  4. Security Analysis β€” Detection of common vulnerabilities (OWASP categories)
  5. Performance Review β€” Algorithmic complexity and optimization suggestions
  6. FastAPI Server β€” Running the agent as a production-ready API server
The agent analyzes code across multiple dimensions:
  • Security β€” SQL injection, XSS, insecure patterns
  • Performance β€” Complexity issues, memory concerns, optimizations
  • Quality β€” Readability, maintainability, documentation
  • Best Practices β€” Industry standards, design patterns

Project Structure

Environment Variables

Configure the Groq model using environment variables:

Installation

Managing Dependencies

Sections: api, streamlit, development

Usage

Option 1: Run Directly

Runs the agent with default test inputs (Python code with security issues).

Option 2: Run as API Server

Server starts at http://localhost:8000. API documentation at /docs. Example API call:

How It Works

ComponentDescription
Groq ModelLLaMA 3.3 70B for comprehensive analysis or 8B for speed
Structured OutputPydantic schemas ensure consistent, typed responses
Web SearchDuckDuckGo for current best practices and security advisories
Security AnalysisOWASP-aligned vulnerability detection
Performance ReviewComplexity analysis and optimization suggestions

Example Output

When you run the agent, you’ll see a beautifully formatted structured output:
The CodeReviewOutput Pydantic model provides fully typed access:

Complete Implementation

main.py

The result contains a typed CodeReviewOutput object that you can access programmatically:

agent.py

schemas.py

upsonic_configs.json

Key Features

Groq’s Ultra-Fast Inference

Groq’s custom LPU (Language Processing Unit) hardware provides:
  • Up to 10x faster inference than GPU-based solutions
  • Low latency variance for production workloads
  • Competitive pricing with high throughput
  • Access to top-tier open-source models

Structured Output with Pydantic

For structured output, pass response_format through the Task:
This ensures:
  • Type-safe, validated responses
  • Consistent output structure
  • Easy integration with downstream systems
  • Automatic schema generation for API documentation

Web Search Integration

The agent uses DuckDuckGo to:
  • Find current security best practices
  • Look up language-specific coding standards
  • Search for recent CVEs and security advisories
  • Discover performance benchmarks and optimization techniques

Specialized Agent Variants

The example includes factory functions for specialized agents:
  • create_security_focused_agent() β€” Security-only analysis
  • create_performance_focused_agent() β€” Performance-only analysis
These use the faster llama-3.1-8b-instant model for quicker, focused reviews.

Repository

View the complete example: Groq Code Review Agent