-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoding_agent.ts
More file actions
69 lines (59 loc) · 2.93 KB
/
Copy pathcoding_agent.ts
File metadata and controls
69 lines (59 loc) · 2.93 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
60
61
62
63
64
65
66
67
68
69
/**
* Coding agent demo (TypeScript) — project context persists across sessions.
*
* Run: npx tsx coding-agent-python/coding_agent.ts
*/
import { StatewaveClient } from "@statewavedev/sdk";
const SUBJECT_ID = "demo-coding-dev-bob-ts";
const SERVER_URL = process.env.STATEWAVE_URL ?? "http://localhost:8100";
const API_KEY = process.env.STATEWAVE_API_KEY;
const CONTEXT_BUDGET = 400;
const SESSION_1 = [
{ messages: [
{ role: "user", content: "I'm Bob, working on a Python FastAPI backend called Taskflow. We use SQLAlchemy with Postgres, Alembic for migrations, and pytest for testing." },
{ role: "assistant", content: "Got it — Taskflow is a FastAPI + SQLAlchemy + Postgres project with Alembic migrations and pytest." },
]},
{ messages: [
{ role: "user", content: "I prefer small focused functions, type hints everywhere, and I use Pydantic for all request/response schemas. No classes unless they add real value." },
{ role: "assistant", content: "Noted — functional style with type hints, Pydantic schemas, classes only when justified." },
]},
{ messages: [
{ role: "user", content: "We decided to model task status as a finite state machine: draft → active → paused → completed → archived. Transitions are enforced in the service layer, not the DB." },
{ role: "assistant", content: "Good pattern — service layer validates transitions. I'll keep that in mind." },
]},
];
const SESSION_2 = [
{ messages: [{ role: "user", content: "Can you help me add a PATCH endpoint to transition task status?" }] },
];
async function main() {
const sw = new StatewaveClient({ baseUrl: SERVER_URL, apiKey: API_KEY });
await sw.deleteSubject(SUBJECT_ID);
console.log("=== Session 1: Developer introduces project and preferences ===");
for (const payload of SESSION_1) {
await sw.createEpisode({ subjectId: SUBJECT_ID, source: "coding-chat", type: "conversation", payload });
}
const r = await sw.compileMemories(SUBJECT_ID);
console.log(`Compiled ${r.memoriesCreated} memories`);
for (const m of r.memories) console.log(` [${m.kind}] ${m.content}`);
console.log("\n=== Session 2: Developer returns, asks for a new feature ===");
for (const payload of SESSION_2) {
await sw.createEpisode({ subjectId: SUBJECT_ID, source: "coding-chat", type: "conversation", payload });
}
await sw.compileMemories(SUBJECT_ID);
const ctx = await sw.getContext({
subjectId: SUBJECT_ID,
task: "Developer wants to add a PATCH endpoint for task status transitions",
maxTokens: CONTEXT_BUDGET,
});
console.log(
`\nContext bundle (${ctx.tokenEstimate}/${CONTEXT_BUDGET} tokens, `
+ `${ctx.facts.length} facts, ${ctx.procedures.length} procedures, ${ctx.episodes.length} episodes):\n`,
);
console.log(ctx.assembledContext);
await sw.deleteSubject(SUBJECT_ID);
}
main().catch((err) => {
console.error(err);
console.error(`Is the Statewave server running at ${SERVER_URL}?`);
process.exit(1);
});