@rowan-agent/agent 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @rowan-agent/agent
2
+
3
+ ## Main Features
4
+
5
+ `@rowan-agent/agent` is the public programming entry point and Agent core for Rowan. It wraps model execution, event subscriptions, tool registration, loop-owned thread delegation, run cancellation, and idle waiting.
6
+
7
+ The package implements a phase-configured Agent loop. The loop executes a configurable sequence of phase definitions through a single base `runPhase()` runner. Built-in phases (route, thread, plan, execute, verify) preserve the default behavior, while custom phase configurations can extend or replace them.
8
+
9
+ ## Architecture
10
+
11
+ `src/agent.ts` provides the `Agent` class and remains the core/facade entrypoint. It calls `src/loop.ts` directly.
12
+
13
+ `src/loop.ts` implements the generic phase-machine loop:
14
+ - Creates the loop runtime from input
15
+ - Resolves the phase configuration (default built-in or custom)
16
+ - Iterates through phases by following transitions (`next`, `stop`, `abort`)
17
+ - Completes the run with an `AgentRunResult`
18
+
19
+ Phase definitions live under `src/loop/`:
20
+ - `phase-config.ts` — `AgentPhaseDefinition`, `AgentPhaseConfig`, validation, and default config factory
21
+ - `built-in-phases.ts` — built-in route, thread, plan, execute, and verify phase definitions
22
+ - `phases.ts` — base `runPhase()` and `runConfiguredPhase()` runners
23
+ - `routing.ts` — route scheduling helper used by the route phase
24
+ - `thread.ts` — thread execution helper used by the thread phase
25
+
26
+ Mutable live runtime state and lifecycle helpers live in `src/loop.ts` with the generic phase-machine boundary.
27
+
28
+ `Agent` keeps a small state object:
29
+
30
+ - `sessionId` identifies the current live run/session.
31
+ - `context` is the current `systemPrompt`, visible messages, tools, and skills snapshot.
32
+ - `model` and `stream` describe the model identity and call path.
33
+ - `tools` are the tools the runtime may expose to the model.
34
+ - `isRunning`, `currentResult`, and `error` describe the current run state.
35
+
36
+ `src/task.ts` and `src/types.ts` expose task helpers, typed protocol phase outputs, `AgentState`, `createAgentState`, `createMessage`, and public Agent types. Runtime-owned core tools are exported by `@rowan-agent/runtime`. `src/index.ts` is the package entry point.
37
+
38
+ The loop consumes adapter-normalized `phase_output` events from `@rowan-agent/protocol` while still accepting `structured_output` events for local scripted streams. Default tool calls are executed through the event-neutral runtime primitive; `agent` translates runtime observations into ordered `AgentEvent`s, conversation messages, attempts, verification, and final `AgentRunResult`.
39
+
40
+ `Agent` intentionally exposes the stable, application-facing run surface: context, model, stream, limits, session id, tool approval hooks, event subscriptions, and cancellation. Durable Session persistence belongs to composition roots through `@rowan-agent/session` contracts, not to `Agent`.
41
+
42
+ ## Usage Flow
43
+
44
+ 1. Prepare `model`, `stream`, and `tools`. Optionally provide skills, limits, and tool approval hooks.
45
+ 2. Create an `Agent` instance.
46
+ 3. Use `subscribe` to listen to events. Logging modules and UIs can both consume this stream.
47
+ 4. Call `run()` with an `AgentRunConfig.context` snapshot to start or continue a conversation turn.
48
+ 5. Pass a loaded `sessionId` and reconstructed context before continuing an existing session, or call `abort()` to stop the current run.
49
+
50
+ ```ts
51
+ import { Agent } from "@rowan-agent/agent";
52
+ import { createMessage } from "@rowan-agent/agent";
53
+ import { createCoreTools } from "@rowan-agent/runtime";
54
+
55
+ const tools = createCoreTools({ root: process.cwd() });
56
+ const agent = new Agent({
57
+ context: {
58
+ systemPrompt: "You are Rowan.",
59
+ messages: [
60
+ createMessage("user", "list the package structure in this project"),
61
+ ],
62
+ tools,
63
+ },
64
+ model: { provider: "openai-compatible", name: "gpt-4.1-mini" },
65
+ stream,
66
+ });
67
+
68
+ agent.subscribe((event) => {
69
+ console.error(event.type);
70
+ });
71
+
72
+ const result = await agent.run();
73
+ console.log(result.outcome.message);
74
+ ```