Analysis agent
The Analysis Agent takes raw JSON results and transforms them into clear, natural language explanations that users can understand.
Data to insights
How the analysis agent transforms raw data into readable insights
def analysis_agent(state: AgentState) -> AgentState:
"""Generate natural language answer from query results"""
question = state["question"]
sql_query = state["sql_query"]
query_result = state["query_result"]
prompt = f"""You are a helpful data analyst. Explain these query results in natural language.
Original Question: {question}
SQL Query Used: {sql_query}
Query Results:
{query_result}
Please provide a clear, concise answer to the original question.
- Format numbers clearly
- Use bullet points for multiple items
- If results are empty, say so clearly
- Don't just repeat the data - provide insights
Answer:"""
response = completion(
model=DEFAULT_MODEL,
messages=[
{"role": "system", "content": AGENT_CONFIGS["analysis_agent"]["system_prompt"]},
{"role": "user", "content": prompt}
],
temperature=0.7 # Slightly creative for natural language
)
state["final_answer"] = response.choices[0].message.content.strip()
return stateThe Analysis Agent uses higher temperature for more natural responses.
Analysis patterns
Matching exercise: Match analysis agent features
Loading practice…
Timed quiz: Quick review
Loading practice…
The Analysis Agent transforms raw SQL results into user-friendly explanations. All five core agents are now built.
Validation checklist: Core agents checklist
Loading practice…