How cisco-outshift-ai-agents/tf-code-reviewer-agntcy-agent works
Project Type and Purpose
• This is an agentic backend microservice (no UI) implemented as a FastAPI application that implements the AGNTCY “Terraform Code Reviewer AI Agent” protocol. It exposes both a REST interface (/api/v1/runs) and an AGP (Agent Gateway Protocol) interface, hosts a LangChain-based “code reviewer” chain that formats prompts and calls OpenAI/Azure LLMs, and provides a Python client for both interfaces.
Main Components
a. External Systems
• GitHub Pull‐Request (source of: diff patch + context files)
• (Optional) Terraform Static Analyzer Agent (provides static_analyzer_output)
• AGP Gateway (agent registry & router)
• OpenAI/Azure OpenAI LLM
b. Infrastructure
• Docker Container (built via Dockerfile / docker-compose.yaml)
• Kubernetes / Helm Deployment (via deployments/helm/tf-code-reviewer-agntcy-agent)
c. API Layer
• FastAPI REST Server (listens on port 8123)
• AGP Server (launched on port 46357 as a background task)
d. Application Core
• main.py: orchestrates startup, env loading, logging, FastAPI app, AGP server
• app/api/routes/stateless_runs.py: handles /api/v1/runs POST
• app/utils/chain.py: constructs a LangChain chain, wraps and formats prompts
• app/utils/wrap_prompt.py: prompt‐templating utility
• app/core/config.py & logging_config.py: environment & JSON‐logging setup
• app/models/models.py: request/response schemas
e. Client Library (client/)
• rest.py: example REST client
• agp_client.py: example AGP client
• langgraph.json: AGP client configuration
Relationships & Data Flows
1. Client (REST or AGP) → FastAPI/AGP Server
2. Server extracts:
• context_files (load .tf files, excluding .tfstate)
• changes (patch diff)
• static_analyzer_output (optional)
3. Server invokes Chain (code_reviewer_chain) → OpenAI/Azure API
4. LLM returns structured review comments → Server responds to client
5. Logging: events are emitted in JSON to stdout (or file/aggregator)
6. Registration: on startup, AGP server registers with AGP Gateway
Architectural Patterns & Principles
• Separation of Concerns: core logic (chain.py, wrap_prompt.py), API layer (routes), config/logging (core), models (models), client (client).
• Background Task: AGP server spun up post‐startup via FastAPI lifespan.
• Dependency Injection: FastAPI provides chain object via app state.
• Microservice: stateless HTTP/AGP interface, no internal database—pure compute.
• 12-Factor: config via env vars, logs to stdout, conformance with container best practices.