Skip to content

Commit 4ff3702

Browse files
author
hemanth-1321
committed
changes
1 parent b4c54cc commit 4ff3702

3 files changed

Lines changed: 25 additions & 116 deletions

File tree

server/agentic/agents/aggregator_agent.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
from server.agentic.agents.nodes import PRState
33
from server.agentic.utils.llm_client import llm
44
from server.servcies.github import post_pr_comment, update_pr_comment
5-
import logging
65

7-
logger = logging.getLogger(__name__)
86

97
def aggregator_agent(state: PRState) -> dict:
108

11-
logger.info("aggregator_agent running")
9+
print("aggregator_agent running")
1210

1311
security = state.get("security_issues", [])
1412
quality = state.get("code_quality_issues", [])
@@ -79,7 +77,7 @@ def aggregator_agent(state: PRState) -> dict:
7977
8078
## Changes
8179
82-
| File(s) | Summary |
80+
|File(s) | Summary |
8381
|------------------|---------|
8482
{chr(10).join(f"| **{file_path.split('/')[-2] if '/' in file_path else 'Root'}** | [Describe changes] |" for file_path in files_changed[:3])}
8583
| ... | ... |

server/agentic/agents/graph.py

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,28 @@
1-
from server.agentic.agents.nodes import (
2-
fetch_context_agent, code_quality_agent, security_agent,
3-
test_agent, performance_agent, PRState, error_handler, with_retry
4-
)
1+
from server.agentic.agents.nodes import fetch_context_agent, code_quality_agent, security_agent, test_agent, performance_agent, PRState
52
from server.agentic.agents.aggregator_agent import aggregator_agent
63
from langgraph.graph import StateGraph, START, END
74

85
graph = StateGraph(PRState)
96

10-
# --- Nodes with error handlers ---
11-
graph.add_node(
12-
"fetch_context_agent",
13-
with_retry(fetch_context_agent),
14-
on_error=error_handler
15-
)
7+
graph.add_node("fetch_context_agent", fetch_context_agent)
8+
graph.add_node("security_agent", security_agent)
9+
graph.add_node("code_quality_agent", code_quality_agent)
10+
graph.add_node("performance_agent", performance_agent)
11+
graph.add_node("test_agent", test_agent)
12+
graph.add_node("aggregator_agent", aggregator_agent)
1613

17-
graph.add_node(
18-
"security_agent",
19-
with_retry(security_agent),
20-
on_error=error_handler
21-
)
22-
23-
graph.add_node(
24-
"code_quality_agent",
25-
with_retry(code_quality_agent),
26-
on_error=error_handler
27-
)
28-
29-
graph.add_node(
30-
"performance_agent",
31-
with_retry(performance_agent),
32-
on_error=error_handler
33-
)
34-
35-
graph.add_node(
36-
"test_agent",
37-
with_retry(test_agent),
38-
on_error=error_handler
39-
)
40-
41-
graph.add_node(
42-
"aggregator_agent",
43-
with_retry(aggregator_agent),
44-
on_error=error_handler
45-
)
46-
47-
# ---- Graph Edges ----
4814
graph.add_edge(START, "fetch_context_agent")
4915
graph.add_edge("fetch_context_agent", "security_agent")
5016
graph.add_edge("fetch_context_agent", "code_quality_agent")
5117
graph.add_edge("fetch_context_agent", "performance_agent")
5218
graph.add_edge("fetch_context_agent", "test_agent")
53-
5419
graph.add_edge("security_agent", "aggregator_agent")
5520
graph.add_edge("code_quality_agent", "aggregator_agent")
5621
graph.add_edge("performance_agent", "aggregator_agent")
5722
graph.add_edge("test_agent", "aggregator_agent")
58-
5923
graph.add_edge("aggregator_agent", END)
6024

25+
6126
# Compile workflow
6227
workflow = graph.compile()
28+

server/agentic/agents/nodes.py

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
from typing import TypedDict, List, Annotated, Optional
1+
from typing import TypedDict, List, Annotated,Optional
22
from operator import add
33
from server.agentic.utils.llm_client import llm
44
from server.agentic.utils.vector_tool import search_vector_tool
5-
import time
6-
import traceback
7-
import logging
8-
9-
logger = logging.getLogger(__name__)
105

116
class SimilarPR(TypedDict):
127
ref_id: str
@@ -24,63 +19,14 @@ class PRState(TypedDict):
2419
code_quality_issues: Annotated[List[str], add]
2520
performance_issues: Annotated[List[str], add]
2621
test_suggestions: Annotated[List[str], add]
27-
commit_sha: int
22+
commit_sha:int
2823
learnings: str
2924
progress_comment_id: Optional[int]
3025
final_review: str
3126
review_complete: bool
32-
agent_failed: Optional[str]
33-
agent_error: Optional[str]
34-
agent_trace: Optional[str]
35-
36-
def with_retry(agent_fn, retries=3, base_delay=1):
37-
"""
38-
Wraps agent nodes with retries + exponential backoff
39-
"""
40-
def wrapper(state: PRState):
41-
attempt = 0
42-
last_exc = None
43-
while attempt < retries:
44-
try:
45-
logger.info(f"Running {agent_fn.__name__} (Attempt {attempt+1}/{retries})")
46-
return agent_fn(state)
47-
except Exception as e:
48-
last_exc = e
49-
delay = base_delay * (2 ** attempt)
50-
logger.error(f"Error in {agent_fn.__name__}: {e}")
51-
logger.debug(traceback.format_exc())
52-
time.sleep(delay)
53-
attempt += 1
54-
logger.critical(f"{agent_fn.__name__} FAILED after {retries} retries")
55-
return {
56-
"agent_failed": agent_fn.__name__,
57-
"agent_error": str(last_exc),
58-
"agent_trace": traceback.format_exc()
59-
}
60-
return wrapper
61-
62-
63-
def error_handler(state: PRState):
64-
failed_node = state.get("agent_failed")
65-
err = state.get("agent_error")
66-
67-
logger.critical(f"Global Error Handler Triggered due to: {failed_node}")
68-
69-
return {
70-
"final_review": f"""
71-
**Agent Failure Detected**
72-
73-
**Failed Node:** {failed_node}
74-
**Error:** {err}
75-
76-
Partial review generated from available agents.
77-
""",
78-
"review_complete": True
79-
}
80-
8127

8228
def fetch_context_agent(state: PRState) -> dict:
83-
logger.info("fetch_context_agent running")
29+
print("fetch_context_agent running")
8430
search_query = f"{state.get('pr_number', '')} {state.get('repo_name', '')}"
8531

8632
raw_similar_pr = search_vector_tool(search_query)
@@ -95,11 +41,11 @@ def fetch_context_agent(state: PRState) -> dict:
9541

9642
learnings = "no past-learnig for now"
9743

44+
# ONLY return the keys you're updating
9845
return {"similar_prs": similar_pr, "learnings": str(learnings)}
9946

100-
10147
def security_agent(state: PRState) -> dict:
102-
logger.info("security_agent running")
48+
print("security_agent running")
10349
learnings = state.get("learnings", "")
10450
context = state.get("similar_prs", [])
10551

@@ -123,12 +69,12 @@ def security_agent(state: PRState) -> dict:
12369
"""
12470
res = llm.invoke(prompt)
12571
issues = [line.strip() for line in res.content.splitlines() if line.strip()]
126-
72+
73+
# ONLY return the security_issues key
12774
return {"security_issues": issues}
12875

129-
13076
def code_quality_agent(state: PRState) -> dict:
131-
logger.info("code_quality_agent running")
77+
print("code_quality_agent running")
13278
learnings = state.get("learnings", "")
13379
context = state.get("similar_prs", [])
13480

@@ -149,12 +95,12 @@ def code_quality_agent(state: PRState) -> dict:
14995
"""
15096
res = llm.invoke(prompt)
15197
issues = [line.strip() for line in res.content.splitlines() if line.strip()]
152-
98+
99+
# ONLY return the code_quality_issues key
153100
return {"code_quality_issues": issues}
154101

155-
156102
def performance_agent(state: PRState) -> dict:
157-
logger.info("performance_agent running")
103+
print("performance_agent running")
158104
learnings = state.get("learnings", "")
159105
context = state.get("similar_prs", [])
160106

@@ -173,12 +119,11 @@ def performance_agent(state: PRState) -> dict:
173119
"""
174120
res = llm.invoke(prompt)
175121
issues = [line.strip() for line in res.content.splitlines() if line.strip()]
176-
122+
177123
return {"performance_issues": issues}
178124

179-
180125
def test_agent(state: PRState) -> dict:
181-
logger.info("test_agent running")
126+
print("test_agent running")
182127
learnings = state.get("learnings", "")
183128
context = state.get("similar_prs", [])
184129

@@ -200,5 +145,5 @@ def test_agent(state: PRState) -> dict:
200145
"""
201146
res = llm.invoke(prompt)
202147
issues = [line.strip() for line in res.content.splitlines() if line.strip()]
203-
148+
204149
return {"test_suggestions": issues}

0 commit comments

Comments
 (0)