Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

Introduce an sqlite event log implementation (#96)

Jaana Dogan07f5cc9a03fb
diff --git a/README.md b/README.md
index 09050f1..4015c36 100644
--- a/README.md
+++ b/README.md
@@ -224,7 +224,7 @@ server:
address: ":8494"
eventlog:
- dir: "eventlog"
+ db_filename: "eventlog/log.sqlite"
health_check:
enabled: true
diff --git a/ax.yaml b/ax.yaml
index 0bb9ce0..44348f6 100644
--- a/ax.yaml
+++ b/ax.yaml
@@ -19,8 +19,8 @@ server:
# Event log configuration
eventlog:
- # Directory where event logs are stored
- dir: "eventlog"
+ # SQLite file for event log storage
+ db_filename: "eventlog/log.sqlite"
health_check:
# Whether to enable active health checking
diff --git a/cmd/ax/serve.go b/cmd/ax/serve.go
index 465cda0..e76d1ff 100644
--- a/cmd/ax/serve.go
+++ b/cmd/ax/serve.go
@@ -20,7 +20,6 @@ import (
"log"
"os"
"os/signal"
- "path"
"syscall"
"github.com/google/ax/agent"
@@ -90,9 +89,8 @@ func runServe(cmd *cobra.Command, args []string) error {
func newControllerFromConfig(ctx context.Context, cfg *config.Config) (*controller.Controller, error) {
// Create event log builder
- eventLogBuilder := func(taskID string) (task.EventLog, error) {
- path := path.Join(cfg.EventLog.Dir, taskID+".jsonl")
- return task.OpenFileEventLog(path)
+ eventLogBuilder := func() (task.EventLog, error) {
+ return task.OpenSQLiteEventLog(cfg.EventLog.SQLiteFilename)
}
// Create planner builder
diff --git a/go.mod b/go.mod
index 09c1544..cbb4982 100644
--- a/go.mod
+++ b/go.mod
@@ -6,6 +6,7 @@ require (
github.com/charmbracelet/huh v0.8.0
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834
github.com/google/uuid v1.6.0
+ github.com/mattn/go-sqlite3 v1.14.37
github.com/spf13/cobra v1.10.2
golang.org/x/net v0.48.0
golang.org/x/sync v0.19.0
diff --git a/go.sum b/go.sum
index 73f39cf..3d08d15 100644
--- a/go.sum
+++ b/go.sum
@@ -139,6 +139,8 @@ github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2J
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
+github.com/mattn/go-sqlite3 v1.14.37 h1:3DOZp4cXis1cUIpCfXLtmlGolNLp2VEqhiB/PARNBIg=
+github.com/mattn/go-sqlite3 v1.14.37/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
diff --git a/internal/config/config.go b/internal/config/config.go
index b364336..e3f71da 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -56,7 +56,7 @@ type ServerConfig struct {
// EventLogConfig configures the event log storage.
type EventLogConfig struct {
- Dir string `yaml:"dir"` // Directory for event log files
+ SQLiteFilename string `yaml:"db_filename"` // SQLite file for event log storage
}
// PlannerConfig configures the planner.
@@ -132,8 +132,8 @@ func (c *Config) setDefaults() {
}
// EventLog defaults
- if c.EventLog.Dir == "" {
- c.EventLog.Dir = "eventlog"
+ if c.EventLog.SQLiteFilename == "" {
+ c.EventLog.SQLiteFilename = "eventlog/log.sqlite"
}
// HealthCheck defaults
@@ -147,8 +147,8 @@ func (c *Config) Validate() error {
if c.Server.Address == "" {
return fmt.Errorf("server.address is required")
}
- if c.EventLog.Dir == "" {
- return fmt.Errorf("eventlog.dir is required")
+ if c.EventLog.SQLiteFilename == "" {
+ return fmt.Errorf("eventlog.db_filename is required")
}
// Validate health check
if c.HealthCheck.Enabled {
diff --git a/internal/controller/controller.go b/internal/controller/controller.go
index c3994e0..1db779e 100644
--- a/internal/controller/controller.go
+++ b/internal/controller/controller.go
@@ -20,7 +20,6 @@ import (
"context"
"fmt"
"os"
- "path"
"sync"
"github.com/google/ax/agent"
@@ -38,7 +37,7 @@ type Controller struct {
inFlightExecutionsMu sync.Mutex
inFlightExecutions map[string]struct{}
registry *Registry
- eventLogBuilder task.EventLogBuilder
+ eventLog task.EventLog
plannerBuilder PlannerBuilder
}
@@ -55,12 +54,6 @@ type Config struct {
// New creates a new controller instance.
func New(ctx context.Context, config Config) (*Controller, error) {
- if config.EventLogBuilder == nil {
- config.EventLogBuilder = func(taskID string) (task.EventLog, error) {
- return task.OpenFileEventLog(path.Join(".", "tasklog", taskID+".jsonl"))
- }
- }
-
// Initialize agent registry
registry, err := NewRegistry(config.HealthCheck)
if err != nil {
@@ -75,10 +68,18 @@ func New(ctx context.Context, config Config) (*Controller, error) {
}
}
+ if config.EventLogBuilder == nil {
+ return nil, fmt.Errorf("event log builder is required")
+ }
+ eventLog, err := config.EventLogBuilder()
+ if err != nil {
+ return nil, fmt.Errorf("failed to create event log: %w", err)
+ }
+
return &Controller{
inFlightExecutions: make(map[string]struct{}),
registry: registry,
- eventLogBuilder: config.EventLogBuilder,
+ eventLog: eventLog,
plannerBuilder: config.PlannerBuilder,
}, nil
}
@@ -130,7 +131,7 @@ func (d *Controller) Exec(ctx context.Context, id string, agentID string, incomi
if agentID == "" {
agentID = plannerAgentID
}
- e := task.DefaultExecutor(d.eventLogBuilder, registry)
+ e := task.DefaultExecutor(d.eventLog, registry)
return e.Exec(ctx, &agent.Task{
ID: id,
AgentID: agentID,
@@ -159,6 +160,9 @@ func (d *Controller) Registry() *Registry {
// Close gracefully shuts down the controller.
func (d *Controller) Close() error {
+ if err := d.eventLog.Close(); err != nil {
+ return fmt.Errorf("failed to close event log: %w", err)
+ }
if err := d.registry.Close(); err != nil {
return fmt.Errorf("failed to close registry: %w", err)
}
diff --git a/internal/controller/task/eventlog.go b/internal/controller/task/eventlog.go
index d2d0375..380c918 100644
--- a/internal/controller/task/eventlog.go
+++ b/internal/controller/task/eventlog.go
@@ -15,11 +15,7 @@
package task
import (
- "bufio"
"context"
- "fmt"
- "os"
- "sync"
"github.com/google/ax/proto"
"google.golang.org/protobuf/encoding/protojson"
@@ -34,84 +30,11 @@ type EventLog interface {
Append(ctx context.Context, event *proto.ExecutionEvent) error
// Events returns all events recorded so far, in append order.
- Events(ctx context.Context) ([]*proto.ExecutionEvent, error)
+ Events(ctx context.Context, id string) ([]*proto.ExecutionEvent, error)
// Close releases the underlying resources and closes the log.
Close() error
}
-// FileEventLog is a durable EventLog that writes one JSON object per line to
-// a file. Each execution should use its own file. The file is created if it does
-// not exist and is opened for appending, so existing events survive restarts.
-//
-// The format is newline-delimited JSON (NDJSON): every Append call writes one
-// complete JSON object followed by a newline, making both concurrent writes
-// and crash recovery safe.
-type FileEventLog struct {
- mu sync.Mutex
- path string
- f *os.File
-}
-
-// OpenFileEventLog opens (or creates) the log file at path.
-// Call Close when the execution is done to release the file handle.
-func OpenFileEventLog(path string) (*FileEventLog, error) {
- f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o644)
- if err != nil {
- return nil, fmt.Errorf("eventlog: open %s: %w", path, err)
- }
- return &FileEventLog{path: path, f: f}, nil
-}
-
var marshalOpts = protojson.MarshalOptions{UseProtoNames: true}
var unmarshalOpts = protojson.UnmarshalOptions{DiscardUnknown: true}
-
-// Append serialises event as a single JSON line and syncs to disk.
-func (l *FileEventLog) Append(_ context.Context, event *proto.ExecutionEvent) error {
- line, err := marshalOpts.Marshal(event)
- if err != nil {
- return fmt.Errorf("eventlog: marshal: %w", err)
- }
-
- l.mu.Lock()
- defer l.mu.Unlock()
-
- if _, err := l.f.Write(append(line, '\n')); err != nil {
- return fmt.Errorf("eventlog: write %s: %w", l.path, err)
- }
- // Sync after every write so a crash does not leave a partial line.
- return l.f.Sync()
-}
-
-// Events reads all complete JSON lines from the beginning of the file.
-func (l *FileEventLog) Events(_ context.Context) ([]*proto.ExecutionEvent, error) {
- l.mu.Lock()
- defer l.mu.Unlock()
-
- if _, err := l.f.Seek(0, 0); err != nil {
- return nil, fmt.Errorf("eventlog: seek %s: %w", l.path, err)
- }
-
- var events []*proto.ExecutionEvent
- scanner := bufio.NewScanner(l.f)
- for scanner.Scan() {
- line := scanner.Bytes()
- if len(line) == 0 {
- continue
- }
- ev := &proto.ExecutionEvent{}
- if err := unmarshalOpts.Unmarshal(line, ev); err != nil {
- // Skip lines that could not be decoded (e.g. truncated by crash).
- continue
- }
- events = append(events, ev)
- }
- return events, scanner.Err()
-}
-
-// Close releases the underlying file handle.
-func (l *FileEventLog) Close() error {
- l.mu.Lock()
- defer l.mu.Unlock()
- return l.f.Close()
-}
diff --git a/internal/controller/task/sqlite.go b/internal/controller/task/sqlite.go
new file mode 100644
index 0000000..506339b
--- /dev/null
+++ b/internal/controller/task/sqlite.go
@@ -0,0 +1,121 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "context"
+ "database/sql"
+ "fmt"
+ "time"
+
+ "github.com/google/ax/proto"
+ _ "github.com/mattn/go-sqlite3"
+)
+
+// SQLiteEventLog is a durable EventLog that persists events in a SQLite database.
+// It is safe for concurrent use.
+type SQLiteEventLog struct {
+ db *sql.DB
+}
+
+// OpenSQLiteEventLog opens (or creates) a SQLite database at path and initializes the event log schema.
+func OpenSQLiteEventLog(path string) (*SQLiteEventLog, error) {
+ db, err := sql.Open("sqlite3", path)
+ if err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: open %s: %w", path, err)
+ }
+
+ // Create table if it doesn't exist
+ if _, err := db.Exec(`
+ CREATE TABLE IF NOT EXISTS event_log (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ task_id TEXT NOT NULL,
+ state INTEGER NOT NULL,
+ payload TEXT NOT NULL,
+ timestamp DATETIME NOT NULL
+ )`); err != nil {
+ db.Close()
+ return nil, fmt.Errorf("sqlite_eventlog: create table: %w", err)
+ }
+
+ // Create index if it doesn't exist
+ if _, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_event_log_task_id ON event_log(task_id)`); err != nil {
+ db.Close()
+ return nil, fmt.Errorf("sqlite_eventlog: create index: %w", err)
+ }
+
+ return &SQLiteEventLog{db: db}, nil
+}
+
+// Append serializes the event to JSON and inserts it into the database.
+func (l *SQLiteEventLog) Append(ctx context.Context, event *proto.ExecutionEvent) error {
+ payload, err := marshalOpts.Marshal(event)
+ if err != nil {
+ return fmt.Errorf("sqlite_eventlog: marshal: %w", err)
+ }
+
+ var timestamp time.Time
+ if event.Timestamp != nil {
+ timestamp = event.Timestamp.AsTime()
+ } else {
+ // Fallback if not set, though caller usually sets it.
+ timestamp = time.Now()
+ }
+
+ _, err = l.db.ExecContext(ctx,
+ "INSERT INTO event_log (task_id, state, payload, timestamp) VALUES (?, ?, ?, ?)",
+ event.TaskId, event.State, string(payload), timestamp)
+
+ if err != nil {
+ return fmt.Errorf("sqlite_eventlog: insert: %w", err)
+ }
+
+ return nil
+}
+
+// Events retrieves all events from the database ordered by insertion order.
+func (l *SQLiteEventLog) Events(ctx context.Context, id string) ([]*proto.ExecutionEvent, error) {
+ rows, err := l.db.QueryContext(ctx, "SELECT payload FROM event_log WHERE task_id = ?", id)
+ if err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: query: %w", err)
+ }
+ defer rows.Close()
+
+ var events []*proto.ExecutionEvent
+ for rows.Next() {
+ var payload string
+ if err := rows.Scan(&payload); err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: scan: %w", err)
+ }
+
+ ev := &proto.ExecutionEvent{}
+ if err := unmarshalOpts.Unmarshal([]byte(payload), ev); err != nil {
+ // Similar to FileEventLog, skip lines that cannot be decoded.
+ continue
+ }
+ events = append(events, ev)
+ }
+
+ if err := rows.Err(); err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: iterate: %w", err)
+ }
+
+ return events, nil
+}
+
+// Close releases the database connection.
+func (l *SQLiteEventLog) Close() error {
+ return l.db.Close()
+}
diff --git a/internal/controller/task/sqlite_test.go b/internal/controller/task/sqlite_test.go
new file mode 100644
index 0000000..b73a899
--- /dev/null
+++ b/internal/controller/task/sqlite_test.go
@@ -0,0 +1,140 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package task
+
+import (
+ "context"
+ "path/filepath"
+ "sync"
+ "testing"
+
+ "github.com/google/ax/proto"
+ "google.golang.org/protobuf/types/known/timestamppb"
+)
+
+func TestSQLiteEventLog_AppendAndEvents(t *testing.T) {
+ ctx := context.Background()
+ dbPath := filepath.Join(t.TempDir(), "test.db")
+
+ log, err := OpenSQLiteEventLog(dbPath)
+ if err != nil {
+ t.Fatalf("failed to open sqlite event log: %v", err)
+ }
+ defer log.Close()
+
+ ev1 := &proto.ExecutionEvent{
+ TaskId: "task-1",
+ State: proto.State_STATE_PENDING,
+ Timestamp: timestamppb.Now(),
+ Inputs: []*proto.Content{
+ {Role: "user", Content: &proto.Content_Text{Text: &proto.TextContent{Text: "hello"}}},
+ },
+ }
+
+ ev2 := &proto.ExecutionEvent{
+ TaskId: "task-1",
+ State: proto.State_STATE_COMPLETED,
+ Timestamp: timestamppb.Now(),
+ Outputs: []*proto.Content{
+ {Role: "assistant", Content: &proto.Content_Text{Text: &proto.TextContent{Text: "world"}}},
+ },
+ }
+
+ if err := log.Append(ctx, ev1); err != nil {
+ t.Fatalf("failed to append ev1: %v", err)
+ }
+ if err := log.Append(ctx, ev2); err != nil {
+ t.Fatalf("failed to append ev2: %v", err)
+ }
+
+ events, err := log.Events(ctx, "task-1")
+ if err != nil {
+ t.Fatalf("failed to read events: %v", err)
+ }
+
+ if len(events) != 2 {
+ t.Fatalf("expected 2 events, got %d", len(events))
+ }
+
+ if events[0].TaskId != "task-1" || events[0].State != proto.State_STATE_PENDING {
+ t.Errorf("ev1 metadata mismatch")
+ }
+ if events[1].TaskId != "task-1" || events[1].State != proto.State_STATE_COMPLETED {
+ t.Errorf("ev2 metadata mismatch")
+ }
+}
+
+func TestSQLiteEventLog_ConcurrentAppend(t *testing.T) {
+ ctx := context.Background()
+ dbPath := filepath.Join(t.TempDir(), "test.db")
+
+ log, err := OpenSQLiteEventLog(dbPath)
+ if err != nil {
+ t.Fatalf("failed to open sqlite event log: %v", err)
+ }
+ defer log.Close()
+
+ var wg sync.WaitGroup
+ numRoutines := 10
+ numEvents := 100
+
+ for i := 0; i < numRoutines; i++ {
+ wg.Add(1)
+ go func(agentIdx int) {
+ defer wg.Done()
+ for j := 0; j < numEvents; j++ {
+ ev := &proto.ExecutionEvent{
+ TaskId: "task-concurrent",
+ State: proto.State(agentIdx % 4), // distribute states 0-3
+ Timestamp: timestamppb.Now(),
+ }
+ if err := log.Append(ctx, ev); err != nil {
+ t.Errorf("concurrent append failed: %v", err)
+ }
+ }
+ }(i)
+ }
+
+ wg.Wait()
+
+ events, err := log.Events(ctx, "task-concurrent")
+ if err != nil {
+ t.Fatalf("failed to read events: %v", err)
+ }
+
+ if len(events) != numRoutines*numEvents {
+ t.Fatalf("expected %d events, got %d", numRoutines*numEvents, len(events))
+ }
+}
+
+func TestSQLiteEventLog_Empty(t *testing.T) {
+ ctx := context.Background()
+ dbPath := filepath.Join(t.TempDir(), "test.db")
+
+ log, err := OpenSQLiteEventLog(dbPath)
+ if err != nil {
+ t.Fatalf("failed to open sqlite event log: %v", err)
+ }
+ defer log.Close()
+
+ events, err := log.Events(ctx, "task-1")
+ if err != nil {
+ t.Fatalf("failed to read events: %v", err)
+ }
+
+ if len(events) != 0 {
+ t.Fatalf("expected 0 events, got %d", len(events))
+ }
+}
diff --git a/internal/controller/task/task.go b/internal/controller/task/task.go
index 7b2702f..d68d8ba 100644
--- a/internal/controller/task/task.go
+++ b/internal/controller/task/task.go
@@ -23,11 +23,11 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)
-type EventLogBuilder func(taskID string) (EventLog, error)
+type EventLogBuilder func() (EventLog, error)
type taskExecutor struct {
id string
- elBuilder EventLogBuilder
+ eventLog EventLog
registry map[string]agent.Agent
}
@@ -38,27 +38,22 @@ func newTaskID(parent, child string) string {
return parent + "-" + child
}
-func DefaultExecutor(b EventLogBuilder, registry map[string]agent.Agent) agent.TaskExecutor {
+func DefaultExecutor(eventLog EventLog, registry map[string]agent.Agent) agent.TaskExecutor {
return &taskExecutor{
id: "",
- elBuilder: b,
+ eventLog: eventLog,
registry: registry,
}
}
func (tm *taskExecutor) Exec(ctx context.Context, t *agent.Task, o agent.OutputHandler) error {
t.ID = newTaskID(tm.id, t.ID)
- el, err := tm.elBuilder(t.ID)
- if err != nil {
- return err
- }
-
a, ok := tm.registry[t.AgentID]
if !ok {
return errors.New("no agent found")
}
- allInputs, state, err := history(ctx, el, t.ID)
+ allInputs, state, err := history(ctx, tm.eventLog, t.ID)
if err != nil {
return err
}
@@ -72,7 +67,7 @@ func (tm *taskExecutor) Exec(ctx context.Context, t *agent.Task, o agent.OutputH
}
return nil
}
- return tm.exec(ctx, t, el, a, allInputs, o)
+ return tm.exec(ctx, t, tm.eventLog, a, allInputs, o)
}
func (tm *taskExecutor) exec(
@@ -84,10 +79,9 @@ func (tm *taskExecutor) exec(
o agent.OutputHandler) error {
child := &taskExecutor{
id: t.ID,
- elBuilder: tm.elBuilder,
+ eventLog: tm.eventLog,
registry: tm.registry,
}
- defer el.Close()
var allOutputs []*proto.Content
outputBuffer := func(outgoing *proto.ProcessResponse) error {
@@ -134,7 +128,7 @@ func (tm *taskExecutor) exec(
}
func history(ctx context.Context, el EventLog, taskID string) ([]*proto.Content, proto.State, error) {
- events, err := el.Events(ctx)
+ events, err := el.Events(ctx, taskID)
if err != nil {
return nil, proto.State_STATE_UNSPECIFIED, err
}
diff --git a/internal/controller/task/task_test.go b/internal/controller/task/task_test.go
index 672a2f4..b81635c 100644
--- a/internal/controller/task/task_test.go
+++ b/internal/controller/task/task_test.go
@@ -43,12 +43,16 @@ func (m *MemoryEventLog) Append(_ context.Context, event *proto.ExecutionEvent)
return nil
}
-func (m *MemoryEventLog) Events(_ context.Context) ([]*proto.ExecutionEvent, error) {
+func (m *MemoryEventLog) Events(_ context.Context, taskID string) ([]*proto.ExecutionEvent, error) {
m.mu.Lock()
defer m.mu.Unlock()
- out := make([]*proto.ExecutionEvent, len(m.events))
- copy(out, m.events)
+ out := make([]*proto.ExecutionEvent, 0)
+ for _, ev := range m.events {
+ if ev.TaskId == taskID {
+ out = append(out, ev)
+ }
+ }
return out, nil
}
@@ -72,10 +76,8 @@ func (m *MemoryEventLog) Close() error {
}
// memoryBuilder returns a new EventLogBuilder that creates a fresh MemoryEventLog per task.
-func memoryBuilder() EventLogBuilder {
- return func(taskID string) (EventLog, error) {
- return &MemoryEventLog{}, nil
- }
+func memoryEventLog() EventLog {
+ return &MemoryEventLog{}
}
func Example() {
@@ -101,7 +103,7 @@ func Example() {
}),
}
- tm := DefaultExecutor(memoryBuilder(), registry)
+ tm := DefaultExecutor(memoryEventLog(), registry)
if err := tm.Exec(ctx, &agent.Task{
ID: "test",
AgentID: "planner",
@@ -139,7 +141,7 @@ func TestTaskManager(t *testing.T) {
}),
}
- tm := DefaultExecutor(memoryBuilder(), registry)
+ tm := DefaultExecutor(memoryEventLog(), registry)
if err := tm.Exec(ctx, &agent.Task{
ID: "root-task",
AgentID: "root",
@@ -210,7 +212,7 @@ func TestFanout(t *testing.T) {
}),
}
- tm := DefaultExecutor(memoryBuilder(), registry)
+ tm := DefaultExecutor(memoryEventLog(), registry)
if err := tm.Exec(ctx, &agent.Task{
ID: "root-task",
AgentID: "root",
@@ -228,18 +230,7 @@ func TestConfirmation(t *testing.T) {
ctx := context.Background()
var runCount int
- logs := map[string]*MemoryEventLog{}
- var logsMu sync.Mutex
- builder := func(taskID string) (EventLog, error) {
- logsMu.Lock()
- defer logsMu.Unlock()
- if l, ok := logs[taskID]; ok {
- return l, nil
- }
- l := &MemoryEventLog{}
- logs[taskID] = l
- return l, nil
- }
+ eventLog := memoryEventLog()
confID := "test-conf-id"
var childDone atomic.Bool
@@ -283,7 +274,7 @@ func TestConfirmation(t *testing.T) {
}),
}
- tm := DefaultExecutor(builder, registry)
+ tm := DefaultExecutor(eventLog, registry)
// First run: child returns a confirmation request.
if err := tm.Exec(ctx, &agent.Task{
@@ -321,11 +312,7 @@ func TestConfirmation(t *testing.T) {
func TestResume(t *testing.T) {
ctx := context.Background()
- dir := t.TempDir()
-
- builder := func(taskID string) (EventLog, error) {
- return OpenFileEventLog(dir + "/test-resume-" + taskID + ".jsonl")
- }
+ eventLog := memoryEventLog()
registry := map[string]agent.Agent{
"root": AgentFunc(func(inputs []*proto.Content, tm agent.TaskExecutor, o agent.OutputHandler) {
@@ -352,7 +339,7 @@ func TestResume(t *testing.T) {
}),
}
- tm := DefaultExecutor(builder, registry)
+ tm := DefaultExecutor(eventLog, registry)
if err := tm.Exec(ctx, &agent.Task{
ID: "root-task",
AgentID: "root",