Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/sentry/seer/autofix/autofix_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
}


def build_step_prompt(step: AutofixStep, group: Group) -> str:
def build_step_prompt(step: AutofixStep, group: Group, user_context: str | None = None) -> str:
"""
Build the prompt for a step using issue details.

Expand All @@ -118,13 +118,24 @@ def build_step_prompt(step: AutofixStep, group: Group) -> str:
Formatted prompt string
"""
config = STEP_CONFIGS[step]
return config.prompt_fn(
prompt = config.prompt_fn(
short_id=group.qualified_short_id or str(group.id),
title=group.title or "Unknown error",
culprit=group.culprit or "unknown",
artifact_key=step.value,
)

parts = [prompt]

user_context = user_context or ""
user_context = user_context.strip()
if user_context:
parts.append("")
parts.append("Use the following user context to aid your thinking")
parts.append(user_context)

return "\n".join(parts)


def get_step_webhook_action_type(step: AutofixStep, is_completed: bool) -> SeerActionType:
step_to_action_type = {
Expand Down Expand Up @@ -179,6 +190,7 @@ def trigger_autofix_explorer(
run_id: int | None = None,
stopping_point: AutofixStoppingPoint | None = None,
intelligence_level: Literal["low", "medium", "high"] = "low",
user_context: str | None = None,
) -> int:
"""
Start or continue an Explorer-based autofix run.
Expand All @@ -200,7 +212,7 @@ def trigger_autofix_explorer(
enable_coding=config.enable_coding,
)

prompt = build_step_prompt(step, group)
prompt = build_step_prompt(step, group, user_context)
prompt_metadata = {"step": step.value}
artifact_key = step.value if config.artifact_schema else None
artifact_schema = config.artifact_schema
Expand Down
7 changes: 7 additions & 0 deletions src/sentry/seer/endpoints/group_ai_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class ExplorerAutofixRequestSerializer(CamelSnakeSerializer):
default="low",
help_text="The intelligence level to use.",
)
user_context = serializers.CharField(
required=False,
max_length=1000,
help_text="Optional user context to append to the step prompt.",
allow_blank=True,
)

def validate(self, data: dict[str, Any]) -> dict[str, Any]:
stopping_point = data.get("stopping_point", None)
Expand Down Expand Up @@ -239,6 +245,7 @@ def _post_explorer(self, request: Request, group: Group) -> Response:
stopping_point=AutofixStoppingPoint(stopping_point) if stopping_point else None,
run_id=data.get("run_id"),
intelligence_level=data["intelligence_level"],
user_context=data.get("user_context"),
)
return Response({"run_id": run_id}, status=202)
except SeerPermissionError as e:
Expand Down
1 change: 1 addition & 0 deletions tests/sentry/seer/endpoints/test_group_ai_autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ def test_stopping_point(self, mock_trigger_explorer):
stopping_point=AutofixStoppingPoint.CODE_CHANGES,
run_id=None,
intelligence_level="low",
user_context=None,
)

@patch("sentry.seer.autofix.autofix._call_autofix")
Expand Down
Loading