Summarizes a list of strings into a single output string — typically used after a Map vertex to aggregate parallel results.
| Field | Type | Description |
|---|---|---|
Input |
*[]string |
List of items to summarize |
| Field | Type | Description |
|---|---|---|
Result |
string |
The generated summary |
Reasoning is captured by WithReasoningLog — no graph output needed.
| Key | Type | Default | Description |
|---|---|---|---|
operation |
string |
required | e.g. "summarize into one concise sentence" |
max_retries |
string |
"3" | Number of retries on error |
Designed for reduce patterns. AISummarizeOp is the natural reduce step after a Map that produced []string. The operation param lets you tailor the format: bullet points, a single sentence, a structured paragraph, or anything else.
Combines four Q1 business highlights into a concise two-sentence executive briefing.
package main
import (
"context"
"encoding/json"
"log"
"os"
"time"
"github.com/akennis/sparsi-go/library"
_ "github.com/akennis/dagor/operator/builtin"
"github.com/panjf2000/ants/v2"
"github.com/akennis/dagor"
"github.com/akennis/dagor/graph"
)
func main() {
items := []string{
"Q1 revenue up 18% year-over-year, driven by enterprise subscriptions",
"Customer churn dropped to 2.3%, lowest in company history",
"New product launch in APAC market exceeded first-month targets by 40%",
"R&D headcount grew by 25 engineers to accelerate the roadmap",
}
library.RegisterConst("items_val", items)
g, err := graph.NewBuilder("summarize_demo").
Vertex("src").Op("items_val").
Output("Result", "items_wire").
Vertex("summarize").Op("AISummarizeOp").
Params(map[string]string{
"operation": "combine these bullet points into a single 2-sentence executive briefing",
}).
Input("Input", "items_wire").
Output("Result", "summary").
Build()
if err != nil {
log.Fatalf("build: %v", err)
}
pool, err := ants.NewPool(4)
if err != nil {
log.Fatalf("pool: %v", err)
}
defer pool.Release()
eng, err := dagor.NewEngine(g, pool)
if err != nil {
log.Fatalf("engine: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := eng.Run(ctx); err != nil {
log.Fatalf("run: %v", err)
}
out := map[string]any{}
if raw, ok := eng.GetOutput("summary"); ok {
out["summary"] = *raw.(*string)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(out)
}