-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-basic-node.ts
More file actions
59 lines (51 loc) · 1.96 KB
/
01-basic-node.ts
File metadata and controls
59 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Example 1 — Basic single-Darwin-node StateGraph.
*
* Runs ONE Darwin agent inside a LangGraph. The agent answers a single
* task and writes its output back to graph state. Trajectory is captured
* automatically and stored in `state.darwinTrajectory`.
*
* Run with:
* npm install darwin-langgraph@alpha @langchain/langgraph darwin-agents@alpha
* npx tsx examples/01-basic-node.ts
*
* Required env (for real LLM call):
* DARWIN_PROVIDER=ollama|claude-cli|openai|anthropic
* (plus provider-specific keys — see darwin-agents README)
*/
import { StateGraph } from "@langchain/langgraph";
import { defineAgent } from "darwin-agents";
import { createDarwinNode, darwinAnnotation } from "../src/index.js";
async function main(): Promise<void> {
const summarizer = defineAgent({
name: "summarizer",
role: "Text Summarizer",
description: "Summarizes any text into exactly 3 bullets.",
systemPrompt:
"You are a summarizer. Return EXACTLY 3 bullet points. No prose around them.",
maxTurns: 2,
});
const State = darwinAnnotation();
const graph = new StateGraph(State)
.addNode("summarize", createDarwinNode(summarizer))
.addEdge("__start__", "summarize")
.compile();
const result = await graph.invoke({
task:
"GEPA (Genetic-Pareto) is a 2024 paper from Stanford that proposes " +
"evolving LLM prompts using a Pareto-front of N=3-5 variants with " +
"text-feedback critics instead of scalar reward. Compare to RLAIF.",
});
console.log("=== Summary ===");
console.log(result.output);
console.log();
console.log("=== Trajectory ===");
console.log(" turns:", result.darwinTrajectory?.turnCount);
console.log(" tools:", result.darwinTrajectory?.toolCalls?.length);
console.log(" mcp invocations:", result.darwinTrajectory?.mcpInvocations);
console.log(" text blocks:", result.darwinTrajectory?.textBlockCount);
}
main().catch((err: unknown) => {
console.error(err);
process.exit(1);
});