feat: add aiops payload query augmentation

This commit is contained in:
aruo
2026-07-05 12:56:20 +08:00
parent 674dd27a48
commit 72a3dbf8c5
8 changed files with 219 additions and 0 deletions
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-07-05
@@ -0,0 +1,53 @@
## Context
`AiOpsService.buildTaskPrompt(...)` already distinguishes two modes:
- `PAYLOAD_TARGETED`: diagnose the supplied alert payload.
- `AUTO_DISCOVERY`: discover active alerts first.
In payload-targeted mode, the prompt includes alert fields, but it does not provide a normalized retrieval query for `lookup_knowledge`. The Agent may still call the tool, but the exact query is left to model behavior.
## Goals / Non-Goals
**Goals:**
- Build a deterministic retrieval query from AIOps payload fields.
- Preserve the original payload fields in the prompt.
- Make the recommended knowledge query visible in prompt text for trace/debugging.
- Keep the Agent responsible for deciding when to call `lookup_knowledge`.
**Non-Goals:**
- Do not add automatic pre-Agent retrieval.
- Do not add verifier logic.
- Do not change tool invocation schema.
- Do not change L0/L1 retrieval internals.
## Decisions
### Decision 1: Prompt-Level Query Augmentation
Add a recommended knowledge query to the payload-targeted prompt instead of calling `lookup_knowledge` directly.
Rationale:
- The current AIOps flow is Agent-driven; tools remain explicit.
- Prompt-level augmentation is low risk and easy to inspect.
- It avoids introducing another hidden retrieval path that would complicate trace semantics.
Alternative considered: automatically call `lookup_knowledge` before invoking the Supervisor. This was rejected because it changes execution behavior and may create evidence that the Agent did not request.
### Decision 2: Preserve Original Query Terms
The generated query includes raw alert/service/symptom terms rather than replacing them with broad domains.
Rationale:
- Alert name, service name, severity, and symptom are high-value retrieval terms.
- Broad categories such as `infrastructure` are useful hints but should not replace concrete terms.
## Risks / Trade-offs
- [Risk] Prompt grows slightly longer. -> Mitigation: keep the query compact and skip blank fields.
- [Risk] The model may ignore the recommendation. -> Mitigation: make the instruction explicit and test prompt inclusion.
- [Risk] Query construction duplicates some summary fields. -> Mitigation: treat the retrieval query as a compact, tool-oriented view of the payload.
@@ -0,0 +1,25 @@
## Why
AIOps payload-targeted diagnosis already scopes the Agent to the supplied alert, but the prompt does not provide a deterministic knowledge-retrieval query. This leaves the Agent to invent lookup terms from the full prompt, which can omit high-value alert fields such as alert name, service, severity, and symptom.
## What Changes
- Build a stable knowledge retrieval query from AIOps payload fields.
- Include the generated retrieval query in payload-targeted prompts as the recommended `lookup_knowledge` query.
- Keep retrieval explicit through the Agent tool; do not automatically call `lookup_knowledge` before the Agent runs.
- Add focused tests for query construction and prompt inclusion.
## Capabilities
### New Capabilities
None.
### Modified Capabilities
- `aiops-traceable-diagnosis-entry`: Payload-targeted AIOps prompts include a deterministic knowledge retrieval query derived from alert payload fields.
## Impact
- Affects `AiOpsService` prompt construction only.
- Does not change the `lookup_knowledge` tool signature, VectorStore retrieval, AIOps API contract, or trace schema.
@@ -0,0 +1,18 @@
## ADDED Requirements
### Requirement: AIOps payload prompts SHALL include a recommended knowledge query
When an AIOps request includes alert payload fields, the system SHALL include a deterministic recommended knowledge retrieval query in the prompt sent to the Agent flow.
#### Scenario: Payload-targeted prompt includes knowledge query
- **WHEN** an AIOps request contains alert name, service, severity, or description
- **THEN** the generated task prompt SHALL include a recommended `lookup_knowledge` query derived from the supplied payload fields
#### Scenario: Query skips blank fields
- **WHEN** some AIOps payload fields are blank
- **THEN** the recommended knowledge query SHALL omit those blank fields
- **AND** it SHALL preserve the non-blank alert-specific terms
#### Scenario: Auto-discovery prompt does not invent payload query
- **WHEN** an AIOps request does not include alert payload fields
- **THEN** the generated task prompt SHALL remain in auto-discovery mode
- **AND** it SHALL not include a payload-derived recommended knowledge query
@@ -0,0 +1,14 @@
## 1. Prompt Query Construction
- [x] 1.1 Add a deterministic AIOps knowledge query builder from payload fields.
- [x] 1.2 Include the recommended query in payload-targeted task prompts.
## 2. Tests And Docs
- [x] 2.1 Add unit tests for query construction and prompt inclusion.
- [x] 2.2 Update interview/RAG notes to reflect AIOps payload query augmentation.
## 3. Verification
- [x] 3.1 Run focused AIOps service tests.
- [x] 3.2 Validate the OpenSpec change and review git scope.