Skip to content

Commit

Permalink
Add summary to coding step, remove preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
roaga committed Sep 4, 2024
1 parent 7e8aa6d commit e942529
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
16 changes: 2 additions & 14 deletions src/seer/automation/autofix/components/coding/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from sentry_sdk.ai.monitoring import ai_track

from seer.automation.agent.agent import AgentConfig, GptAgent
from seer.automation.agent.client import GptClient
from seer.automation.agent.models import Message
from seer.automation.autofix.autofix_context import AutofixContext
from seer.automation.autofix.components.coding.models import (
CodingOutput,
Expand Down Expand Up @@ -45,17 +43,6 @@ def invoke(self, request: CodingRequest) -> CodingOutput | None:
config=AgentConfig(system_prompt=CodingPrompts.format_system_msg()),
)

# preprocess event information
event_details_response, _ = GptClient().completion(
messages=[
Message(
content=f"We have lots of information available for debugging an issue in our code below. Reproduce the info exactly as it is now, but exclude any useless information.\n\n{request.event_details.format_event()}"
),
],
model="gpt-4o-mini-2024-07-18",
)
simplified_event_details = event_details_response.content

task_str = (
RootCausePlanTaskPromptXml.from_root_cause(request.root_cause_and_fix).to_prompt_str()
if isinstance(request.root_cause_and_fix, RootCauseAnalysisItem)
Expand All @@ -66,8 +53,9 @@ def invoke(self, request: CodingRequest) -> CodingOutput | None:

response = agent.run(
CodingPrompts.format_fix_discovery_msg(
event=simplified_event_details,
event=request.event_details.format_event(),
task_str=task_str,
summary=request.summary,
repo_names=[repo.full_name for repo in state.request.repos],
instruction=request.instruction,
),
Expand Down
4 changes: 3 additions & 1 deletion src/seer/automation/autofix/components/coding/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import textwrap
from typing import Annotated
from typing import Annotated, Optional

from pydantic import BaseModel, StringConstraints, field_validator
from pydantic_xml import attr, element
Expand All @@ -10,12 +10,14 @@
)
from seer.automation.component import BaseComponentOutput, BaseComponentRequest
from seer.automation.models import EventDetails, PromptXmlModel
from seer.automation.summarize.issue import IssueSummary


class CodingRequest(BaseComponentRequest):
event_details: EventDetails
root_cause_and_fix: RootCauseAnalysisItem | str
instruction: str | None = None
summary: Optional[IssueSummary] = None


class SnippetXml(PromptXmlModel, tag="snippet"):
Expand Down
15 changes: 11 additions & 4 deletions src/seer/automation/autofix/components/coding/prompts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import textwrap
from typing import Optional

from seer.automation.autofix.components.coding.models import PlanStepsPromptXml
from seer.automation.autofix.prompts import format_instruction, format_repo_names
from seer.automation.autofix.prompts import format_instruction, format_repo_names, format_summary
from seer.automation.summarize.issue import IssueSummary


class CodingPrompts:
Expand All @@ -20,14 +22,18 @@ def format_system_msg():

@staticmethod
def format_fix_discovery_msg(
event: str, task_str: str, repo_names: list[str], instruction: str | None
event: str,
task_str: str,
repo_names: list[str],
instruction: str | None,
summary: Optional[IssueSummary] = None,
):
return textwrap.dedent(
"""\
{repo_names_str}
Given the issue:
Given the issue: {summary_str}
{event_str}
{instruction}
The root cause of the issue has been identified and context about the issue has been provided:
{task_str}
Expand All @@ -53,6 +59,7 @@ def format_fix_discovery_msg(
task_str=task_str,
repo_names_str=format_repo_names(repo_names),
instruction=format_instruction(instruction),
summary_str=format_summary(summary),
)

@staticmethod
Expand Down
15 changes: 15 additions & 0 deletions src/seer/automation/autofix/steps/coding_step.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from langfuse.decorators import observe
from pydantic import ValidationError
from sentry_sdk.ai.monitoring import ai_track

from celery_app.app import celery_app
Expand All @@ -18,6 +19,8 @@
from seer.automation.autofix.steps.steps import AutofixPipelineStep
from seer.automation.models import EventDetails
from seer.automation.pipeline import PipelineStepTaskRequest
from seer.automation.summarize.issue import IssueSummary
from seer.db import DbIssueSummary, Session


class AutofixCodingStepRequest(PipelineStepTaskRequest):
Expand Down Expand Up @@ -67,11 +70,23 @@ def _invoke(self, **kwargs):
event_details = EventDetails.from_event(state.request.issue.events[0])
self.context.process_event_paths(event_details)

group_id = state.request.issue.id
summary = state.request.issue_summary
if not summary:
with Session() as session:
group_summary = session.get(DbIssueSummary, group_id)
if group_summary:
try:
summary = IssueSummary.model_validate(group_summary.summary)
except ValidationError:
pass

coding_output = CodingComponent(self.context).invoke(
CodingRequest(
event_details=event_details,
root_cause_and_fix=root_cause_and_fix,
instruction=state.request.instruction,
summary=summary,
)
)

Expand Down

0 comments on commit e942529

Please sign in to comment.