Skip to content

Analysis Agent API

Developer Reference

This page covers internal implementation details. It is not included in the User Guide.

The Analysis Agent handles factual infrastructure Q&A. It accepts a user query and estate context, reasons over structured data using Claude with tool-assisted computation, and returns a streamed response.

v3 (shipped) vs v4 (designed)

This page documents the shipped v3-analysis-agent-go service, which per its repo README "answers factual questions about AWS infrastructure data using Claude Sonnet" with two modes (standard, broad) and two tools (inspect_schema, compute_stats). The v4 spec describes a richer multi-domain Analysis Agent that emits a structured semantic payload keyed to template blocks via the Context Manager → UI Agent path; that is designed but not yet the live API. Treat the contract here as the v3 surface.

Base URL: http://analysis-agent:8081


Endpoints

POST /api/v1/analyze

Accepts an analysis request and returns a Server-Sent Events (SSE) stream.

Headers:

Content-Type: application/json

Request body:

json
{
  "query":      "How many EC2 instances are running in us-east-1?",
  "context":    "<raw JSON string from client>",
  "target":     "H",
  "mode":       "standard",
  "prompt":     { "m": {}, "t": "2026-05-05T12:00:00Z" },
  "profile":    {},
  "id":         "client-device-id",
  "request_id": "req-abc123"
}
FieldTypeRequiredDescription
querystringYes*The user's natural-language question. If empty, extracted from the latest user message in prompt.m
contextstringYesRaw JSON string from the client estate — parsed internally for structured data arrays
targetstringYesAlways "H" for this agent. The gateway translates legacy "br" to "H" + mode="broad"
modestringNo"standard" (default) or "broad". Controls which system prompt is used
promptobjectNoFull conversation history. See Conversation History
profileobjectNoProfile data passed through to UI Agent for rendering context
idstringNoClient identifier for log correlation
request_idstringNoRequest identifier for log correlation

Max body size: 10 MB


GET /health

bash
curl http://analysis-agent:8081/health
json
{ "service": "analysis-agent", "status": "healthy" }

Conversation history

The prompt field carries the full conversation history across turns.

json
{
  "m": {
    "0": { "r": 0, "c": "What are my EC2 instances?" },
    "1": { "r": 1, "c": "I found 12 instances in us-east-1." },
    "2": { "r": 0, "c": "How many are running?" }
  },
  "t": "2026-05-05T12:00:00Z"
}
FieldDescription
mMessage map — keys are message index strings
m[n].rRole: 0 = user, 1 = assistant
m[n].cContent — the message text
tTimestamp of the conversation start

The full conversation history is passed to the UI Agent for coherent multi-turn rendering.


Modes

ModeSystem promptBehaviour
standardprompts/analysis-agent-v3.txtFull analysis — may include recommendations, findings suggestions
broadprompts/analysis-agent-broad.txtFacts only — plain prose, no recommendations, no findings

broad mode is used for initial estate overview queries where recommendations would be premature.


SSE response events

The response is a stream of Server-Sent Events. Each event has a type and data:

Event typeDescription
text_deltaStreamed text chunk from the LLM
tool_useThe LLM requested a tool call — includes tool name and input
tool_resultResult of a tool call — returned to the LLM
direct_responseFallback — plain text response if UI Agent is unavailable
errorError event — includes error code and message
doneStream complete

Example stream:

event: tool_use
data: {"name": "inspect_schema", "input": {"data_key": "ec2_instances"}}

event: tool_result
data: {"result": {"fields": ["id", "type", "state", "region", "tags"], "count": 48}}

event: text_delta
data: {"text": "There are 48 EC2 instances in your estate. "}

event: text_delta
data: {"text": "In us-east-1: 31 instances. Of those, 12 have no Name tag."}

event: done
data: {}

Tools

The Analysis Agent uses two tools internally for structured computation over estate data:

inspect_schema

Inspects the schema of a structured data array in the context payload.

json
{
  "name": "inspect_schema",
  "input": {
    "data_key": "ec2_instances"
  }
}

Returns: { "fields": [...], "count": N, "sample": {...} }

The LLM sees metadata — not raw data. This prevents the LLM from reasoning over thousands of raw resource records.

compute_stats

Computes aggregate statistics over a structured data array.

json
{
  "name": "compute_stats",
  "input": {
    "data_key": "ec2_instances",
    "group_by": "region",
    "filter": { "state": "running" },
    "metrics": ["count"]
  }
}

Returns: { "groups": { "us-east-1": 31, "us-west-2": 17 }, "total": 48 }


Error handling

HTTP statusCondition
400Malformed request — missing query and no messages in prompt.m, or invalid JSON
413Request body exceeds 10 MB
500Internal error — LLM call failed, context parsing error
503UI Agent unavailable — falls back to direct_response event

Timeout: 120 seconds. Long queries over large estate contexts may approach this limit.


Gateway integration

The gateway routes requests to this agent based on intent classification:

Gateway targetAgentNotes
"H" with mode="standard"Analysis AgentStandard Q&A
"H" with mode="broad"Analysis AgentFacts-only, broad mode
"br" (legacy)Analysis AgentTranslated to "H" + mode="broad" at gateway

Other target values are routed to different agents (Playbook Agent, Autoresolver, etc.).


Example request (curl)

bash
curl -N -X POST http://analysis-agent:8081/api/v1/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How many S3 buckets have public read access?",
    "context": "{\"s3_buckets\": [{\"name\": \"prod-logs\", \"acl\": \"public-read\"}, ...]}",
    "target": "H",
    "mode": "standard",
    "request_id": "req-demo-001"
  }'

The -N flag disables curl buffering so SSE events stream in real time.


Next steps

Escher — Agentic CloudOps by Tessell