Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Introduce the conversation log (#182)

Jaana Dogane8eb96f37406
diff --git a/README.md b/README.md
index bdbe0e3..295f8b9 100644
--- a/README.md
+++ b/README.md
@@ -75,7 +75,7 @@ ax exec --input "Can you list me this directory?" --config my-config.yaml
You can continue an execution any time:
```bash
-ax exec --id exec123 --input "Show me the contents of README.md"
+ax exec --conversation d85a4b4e-c53b-4c84-b879-f10d905bce40 --input "Show me the contents of README.md"
```
Instead of running the default planner agent, you can run any registered agent:
@@ -86,7 +86,7 @@ ax exec --agent coding --input "Can you write me a simple HTTP server in Python?
You can resume an incomplete execution:
```bash
-ax exec --resume --agent "coding" --id "edf98ef5-4bb1-4a9e-a091-3a77e03727e6"
+ax exec --resume --agent "coding" --conversation "edf98ef5-4bb1-4a9e-a091-3a77e03727e6"
```
### 2. Run exec with Custom Agents
@@ -121,7 +121,7 @@ The server exposes the `AXService` on port `:8494` by default.
```bash
ax exec \
--server localhost:8494 \
- --id task123 \
+ --conversation 550e8400-e29b-41d4-a716-446655440000 \
--input "HELLO, CAN YOU LOWERCASE WHAT I JUST SAID?"
```
@@ -134,17 +134,17 @@ The `ax` command provides several subcommands:
```bash
ax exec \
--input <text> \
- [--id <id>] \
+ [--conversation <id>] \
[--agent <id>] \
[--server <address>] \
[--config <file>]
```
-Executes a new agentic execution or automatically resumes an existing one. If the ID already exists, the execution will be resumed from its last state with the new input (if any).
+Executes a new agentic execution or automatically resumes an existing one. If the conversation ID already exists, the execution will be resumed from its last state with the new input (if any).
Options:
- `--input`: Input message to send to agents (required)
-- `--id`: Unique identifier (optional, generates UUID if not provided, or resumes if exists)
+- `--conversation`: Conversation ID (optional, generates UUID if not provided, or resumes if exists)
- `--agent`: Agent ID to use (optional, defaults to planner)
- `--server`: gRPC controller server address (optional. If not provided, runs with a built-in server)
- `--config`: Path to YAML configuration file (only used with a built-in server, default: "ax.yaml")
@@ -156,7 +156,7 @@ Options:
ax exec --input "Hello agents!"
# Resume an existing execution with new input
-ax exec --id abc123 --input "Ok, now let's do something else..."
+ax exec --conversation a53d4db3-1165-4925-87da-be6c72bbdeb1 --input "Ok, now let's do something else..."
# Execute using server mode
ax exec --server localhost:8494 --input "Hello agents!"
@@ -188,13 +188,13 @@ Options:
```bash
# Fork from the latest state
-ax fork --src-id abc123
+ax fork --src-id 38460323-9a78-41cb-8991-022b0ff2c19c
# Fork from a specific checkpoint
-ax fork --src-id abc123 --src-checkpoint "550e..."
+ax fork --src-id 38460323-9a78-41cb-8991-022b0ff2c19c --src-checkpoint "550e..."
# Fork from a specific checkpoint to a new event log with a specific new ID
-ax fork --src-id abc123 --src-checkpoint "550e..." --dest-id new-id
+ax fork --src-id 38460323-9a78-41cb-8991-022b0ff2c19c --src-checkpoint "550e..." --dest-id e5e26e38-53a2-4f22-b1cb-ae867357df83
```
@@ -203,7 +203,7 @@ ax fork --src-id abc123 --src-checkpoint "550e..." --dest-id new-id
Visualize the trace of an agentic execution in a Web UI, directly fetching from the SQLite event log.
```bash
-ax trace --id <id> [--server <server-address>] [--config <file>]
+ax trace --conversation <id> [--addr <address>] [--config <file>]
```
This will parse the execution logs and spin up a local web server (defaulting to e.g. `http://localhost:8080`), automatically opening it in your browser.
@@ -216,10 +216,10 @@ Options:
```bash
# Trace on default server localhost:8080
-ax trace --id 1a6e0b29-87c2-4af0-81ac-0c73bf8fa293
+ax trace --conversation 1a6e0b29-87c2-4af0-81ac-0c73bf8fa293
# Trace on a custom server address and port
-ax trace --id 1a6e0b29-87c2-4af0-81ac-0c73bf8fa293 --addr 0.0.0.0:9090
+ax trace --conversation 1a6e0b29-87c2-4af0-81ac-0c73bf8fa293 --addr 0.0.0.0:9090
```
### Register
diff --git a/cmd/ax/exec.go b/cmd/ax/exec.go
index 77df032..62e826d 100644
--- a/cmd/ax/exec.go
+++ b/cmd/ax/exec.go
@@ -33,29 +33,29 @@ import (
)
var (
- execID string
- execAgentID string
- execInput string
- execServerAddr string
- execConfigFile string
- execResume bool // allow resuming an execution without inputs
+ execConversationID string
+ execAgentID string
+ execInput string
+ execServerAddr string
+ execConfigFile string
+ execResume bool // allow resuming an execution without inputs
)
var execCmd = &cobra.Command{
Use: "exec",
- Short: "Execute a task or resume an existing one",
- Long: `Execute a new agentic task or resume an existing one.
-If no ID is provided, a new UUID will be generated.`,
+ Short: "Execute a conversation or resume an existing one",
+ Long: `Execute a new conversation or resume an existing one.
+If no conversation ID is provided, a new UUID will be generated.`,
RunE: runExec,
}
func init() {
- execCmd.Flags().StringVar(&execID, "id", "", "ID (optional, generates UUID if not provided)")
+ execCmd.Flags().StringVar(&execConversationID, "conversation", uuid.NewString(), "Conversation ID (optional, generates UUID if not provided)")
execCmd.Flags().StringVar(&execAgentID, "agent", "", "Agent ID (optional, planner is used if not specified)")
execCmd.Flags().StringVar(&execInput, "input", "", "Input message to send (optional)")
execCmd.Flags().StringVar(&execServerAddr, "server", "", "gRPC controller server address (if specified, connects to remote server; otherwise runs with a local built-in AX server)")
execCmd.Flags().StringVar(&execConfigFile, "config", "ax.yaml", "Path to YAML configuration file (only used with a local built-in AX server)")
- execCmd.Flags().BoolVar(&execResume, "resume", false, "Resume an execution without inputs")
+ execCmd.Flags().BoolVar(&execResume, "resume", false, "Resume a conversation without inputs")
execCmd.MarkFlagsMutuallyExclusive("input", "resume")
}
@@ -68,11 +68,6 @@ var (
func runExec(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
- // Generate UUID if no ID provided
- if execID == "" {
- execID = uuid.New().String()
- }
-
// Setup signal handling for graceful shutdown
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@@ -89,23 +84,25 @@ func runExec(cmd *cobra.Command, args []string) error {
cancel()
}()
- return execLoop(ctx, execID, execAgentID, execInput)
+ return execLoop(ctx, execConversationID, execAgentID, execInput)
}
func execLoop(ctx context.Context, id string, agentID string, input string) error {
d := internal.NewDisplay(id)
d.DisplayHeader()
- var history []*proto.Message
+ var inputs []*proto.Message
if !execResume {
- input, quit, err := promptUser(d, input)
+ var quit bool
+ var err error
+ input, quit, err = promptUser(d, input)
if err != nil {
return err
}
if quit {
return nil
}
- history = []*proto.Message{
+ inputs = []*proto.Message{
{
Role: "user",
Content: &proto.Content{
@@ -120,11 +117,10 @@ func execLoop(ctx context.Context, id string, agentID string, input string) erro
}
for {
- conf, outputs, err := runAutoExec(ctx, d, id, agentID, history)
+ conf, err := runAutoExec(ctx, d, id, agentID, inputs)
if err != nil {
return err
}
- history = append(history, outputs...)
if conf != nil {
for {
@@ -162,53 +158,43 @@ func execLoop(ctx context.Context, id string, agentID string, input string) erro
},
}}
}
- // The task is still pending, we need to only send the answer.
- // not the full history. Because we executor will put the full
- // history together.
- conf, outputs, err = runAutoExec(ctx, d, id, agentID, decision)
+
+ conf, err = runAutoExec(ctx, d, id, agentID, decision)
if err != nil {
return err
}
- history = append(history, decision...)
- history = append(history, outputs...)
if conf == nil {
break
}
}
}
- // Once we finished a task, we should start another one
- // to continue the conversation with history.
- id = uuid.NewString()
- d := internal.NewDisplay(id)
- d.DisplayHeader()
-
- // Remove all the function calls, confirmations,
- // and function responses. They are not relevant
- // for the upcoming executions.
- history = resetHistory(history)
-
- input, quit, err := promptUser(d, "")
+ var quit bool
+ input, quit, err = promptUser(d, "")
if err != nil {
return err
}
if quit {
return nil
}
- history = append(history, &proto.Message{
- Role: "user",
- Content: &proto.Content{
- Content: &proto.Content_Text{
- Text: &proto.TextContent{
- Text: input,
+
+ inputs = []*proto.Message{
+ {
+ Role: "user",
+ Content: &proto.Content{
+ Content: &proto.Content_Text{
+ Text: &proto.TextContent{
+ Text: input,
+ },
},
},
},
- })
+ }
+ agentID = "" // reset agent id for next turn
}
}
-func runAutoExec(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, []*proto.Message, error) {
+func runAutoExec(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, error) {
fn := runExecHeadless
if execServerAddr != "" {
fn = runExecServer
@@ -216,74 +202,62 @@ func runAutoExec(ctx context.Context, d *internal.Display, id string, agentID st
return fn(ctx, d, id, agentID, inputs)
}
-func runExecHeadless(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, []*proto.Message, error) {
+func runExecHeadless(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, error) {
if execController == nil {
cfg, err := config.LoadFromFile(execConfigFile)
if err != nil {
- return nil, nil, fmt.Errorf("error loading config file '%s': %w", execConfigFile, err)
+ return nil, fmt.Errorf("error loading config file '%s': %w", execConfigFile, err)
}
c, err := newControllerFromConfig(ctx, cfg)
if err != nil {
- return nil, nil, fmt.Errorf("error creating controller: %w", err)
+ return nil, fmt.Errorf("error creating controller: %w", err)
}
execController = c
}
- var checkpoint string
- var outputs []*proto.Message
var confirmation *proto.ConfirmationContent
outputHandler := agent.OutputHandler(func(resp *proto.AgentOutputs) error {
- if resp.CheckpointId != "" {
- checkpoint = resp.CheckpointId
- }
-
for _, m := range resp.Messages {
if conf := m.GetContent().GetConfirmation(); conf != nil {
confirmation = conf
}
}
- outputs = append(outputs, resp.Messages...)
displayContents(d, resp.Messages)
return nil
})
- if err := execController.Exec(ctx, &proto.AgentMessage{
- ExecId: id,
- Msg: &proto.AgentMessage_Start{
- Start: &proto.AgentStart{
- AgentId: agentID,
- Messages: inputs,
- },
- },
+ if err := execController.Exec(ctx, &proto.ExecRequest{
+ ConversationId: id,
+ AgentId: agentID,
+ Inputs: inputs,
}, outputHandler); err != nil {
- return nil, nil, fmt.Errorf("error executing with local server: %w", err)
+ return nil, fmt.Errorf("error executing with local server: %w", err)
}
if confirmation == nil {
- d.FinishOutput(checkpoint)
+ d.FinishOutput("")
}
- return confirmation, outputs, nil
+ return confirmation, nil
}
-func runExecServer(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, []*proto.Message, error) {
+func runExecServer(ctx context.Context, d *internal.Display, id string, agentID string, inputs []*proto.Message) (*proto.ConfirmationContent, error) {
conn, err := connect(execServerAddr)
if err != nil {
- return nil, nil, err
+ return nil, err
}
defer conn.Close()
client := proto.NewAXServiceClient(conn)
stream, err := client.Exec(ctx, &proto.ExecRequest{
- Id: id,
- AgentId: agentID,
- Inputs: inputs,
+ ConversationId: id,
+ AgentId: agentID,
+ Inputs: inputs,
})
if err != nil {
- return nil, nil, fmt.Errorf("error executing: %w", err)
+ return nil, fmt.Errorf("error executing: %w", err)
}
var checkpoint string
- var outputs []*proto.Message
var confirmation *proto.ConfirmationContent
for {
resp, err := stream.Recv()
@@ -291,7 +265,7 @@ func runExecServer(ctx context.Context, d *internal.Display, id string, agentID
break
}
if err != nil {
- return nil, nil, fmt.Errorf("error receiving response: %w", err)
+ return nil, fmt.Errorf("error receiving response: %w", err)
}
if resp.Outputs != nil {
for _, m := range resp.Outputs {
@@ -299,14 +273,13 @@ func runExecServer(ctx context.Context, d *internal.Display, id string, agentID
confirmation = conf
}
}
- outputs = append(outputs, resp.Outputs...)
displayContents(d, resp.Outputs)
}
}
if confirmation == nil {
d.FinishOutput(checkpoint)
}
- return confirmation, outputs, nil
+ return confirmation, nil
}
func displayContents(d *internal.Display, contents []*proto.Message) {
@@ -334,24 +307,6 @@ func displayContents(d *internal.Display, contents []*proto.Message) {
}
}
-func resetHistory(history []*proto.Message) []*proto.Message {
- var out []*proto.Message
- for _, m := range history {
- content := m.GetContent()
- if content.GetFunctionCall() != nil {
- continue
- }
- if content.GetFunctionResponse() != nil {
- continue
- }
- if content.GetConfirmation() != nil {
- continue
- }
- out = append(out, m)
- }
- return out
-}
-
// promptUser loops until the user provides a non-empty input string.
// It returns:
// - string: the valid user input
@@ -369,6 +324,7 @@ func promptUser(d *internal.Display, input string) (string, bool, error) {
d.DisplayInput(input)
if strings.ToLower(strings.TrimSpace(input)) == "q" {
fmt.Println("Goodbye!")
+ fmt.Printf("To resume this conversation, ax exec --conversation %s\n", execConversationID)
return "", true, nil
}
return input, false, nil
diff --git a/cmd/ax/fork.go b/cmd/ax/fork.go
index 306daa6..b4e9758 100644
--- a/cmd/ax/fork.go
+++ b/cmd/ax/fork.go
@@ -15,11 +15,6 @@
package main
import (
- "context"
- "fmt"
-
- "github.com/google/ax/proto"
- "github.com/google/uuid"
"github.com/spf13/cobra"
)
@@ -48,35 +43,5 @@ func init() {
}
func runFork(cmd *cobra.Command, args []string) error {
- ctx := cmd.Context()
-
- // Generate UUID if no destination ID provided
- if forkDestID == "" {
- forkDestID = uuid.New().String()
- fmt.Printf("Generated destination ID: %s\n", forkDestID)
- }
-
- conn, err := connect(forkServerAddr)
- if err != nil {
- return err
- }
- defer conn.Close()
-
- client := proto.NewAXServiceClient(conn)
-
- _, err = Fork(ctx, client, forkSourceID, forkCheckpointID, forkDestID)
- return err
-}
-
-// Fork forks a execution from a checkpoint and returns the new execution ID.
-func Fork(ctx context.Context, client proto.AXServiceClient, sourceID, checkpointID, destID string) (string, error) {
- resp, err := client.Fork(ctx, &proto.ForkRequest{
- SrcId: sourceID,
- SrcCheckpointId: checkpointID,
- DestId: destID,
- })
- if err != nil {
- return "", fmt.Errorf("error forking: %w", err)
- }
- return resp.NewId, nil
+ panic("forking not implemented")
}
diff --git a/cmd/ax/internal/display.go b/cmd/ax/internal/display.go
index ec3d1df..c974010 100644
--- a/cmd/ax/internal/display.go
+++ b/cmd/ax/internal/display.go
@@ -81,7 +81,7 @@ func (d *Display) FinishOutput(checkpointID string) {
}
func (d *Display) DisplayHeader() {
- fmt.Println(d.idStyle.Render("ID: " + d.id))
+ fmt.Println(d.idStyle.Render("Conversation: " + d.id))
fmt.Println()
}
diff --git a/cmd/ax/trace.go b/cmd/ax/trace.go
index 9c93c9a..e6c932b 100644
--- a/cmd/ax/trace.go
+++ b/cmd/ax/trace.go
@@ -69,7 +69,7 @@ type TraceData struct {
}
var (
- traceID string
+ conversationID string
traceServerAddr string
traceConfigFile string
)
@@ -81,21 +81,21 @@ var traceCmd = &cobra.Command{
}
func init() {
- traceCmd.Flags().StringVar(&traceID, "id", "", "Execution ID")
+ traceCmd.Flags().StringVar(&conversationID, "conversation", "", "Conversation ID")
traceCmd.Flags().StringVar(&traceServerAddr, "addr", "localhost:8080", "Server address to listen on")
traceCmd.Flags().StringVar(&traceConfigFile, "config", "ax.yaml", "Path to YAML configuration file")
- traceCmd.MarkFlagRequired("id")
+ traceCmd.MarkFlagRequired("conversation")
}
func runTrace(cmd *cobra.Command, args []string) error {
// Load trace data
- data, err := loadTraceData(cmd.Context(), traceID)
+ data, err := loadTraceData(cmd.Context(), conversationID)
if err != nil {
return fmt.Errorf("error loading trace data: %w", err)
}
if len(data.Execs) == 0 {
- return fmt.Errorf("no trace data found for execution ID: %s", traceID)
+ return fmt.Errorf("no trace data found")
}
// Start HTTP server on specified address
@@ -107,11 +107,11 @@ func runTrace(cmd *cobra.Command, args []string) error {
return serveTraceUI(listener, data, indexHTML)
}
-func loadTraceData(ctx context.Context, rootExecID string) (*TraceData, error) {
+func loadTraceData(ctx context.Context, convID string) (*TraceData, error) {
// The trace command uses the config provided by --config flag
configPath := traceConfigFile
- events, err := fetchEventsFromDB(ctx, configPath, rootExecID)
+ events, rootExecID, err := fetchEventsByConversation(ctx, configPath, convID)
if err != nil {
return nil, err
}
@@ -124,24 +124,51 @@ func loadTraceData(ctx context.Context, rootExecID string) (*TraceData, error) {
return data, nil
}
-func fetchEventsFromDB(ctx context.Context, configPath string, rootExecID string) ([]*proto.ExecutionEvent, error) {
+
+
+func fetchEventsByConversation(ctx context.Context, configPath string, convID string) ([]*proto.ExecutionEvent, string, error) {
cfg, err := config.LoadFromFile(configPath)
if err != nil {
- return nil, fmt.Errorf("error loading config: %w", err)
+ return nil, "", fmt.Errorf("error loading config: %w", err)
}
evLog, err := executor.OpenSQLiteEventLog(cfg.EventLog.SQLiteConfig.Filename)
if err != nil {
- return nil, fmt.Errorf("could not open sqlite eventlog: %w", err)
+ return nil, "", fmt.Errorf("could not open sqlite eventlog: %w", err)
}
defer evLog.Close()
- events, err := evLog.EventsByPrefix(ctx, rootExecID)
+ convEvents, err := evLog.Events(ctx, convID)
if err != nil {
- return nil, fmt.Errorf("failed to query trace events: %w", err)
+ return nil, "", fmt.Errorf("failed to query conversation events: %w", err)
+ }
+
+ var execIDs []string
+ seen := make(map[string]bool)
+ for _, ev := range convEvents {
+ if ev.ExecId != "" && !seen[ev.ExecId] {
+ execIDs = append(execIDs, ev.ExecId)
+ seen[ev.ExecId] = true
+ }
}
- return events, nil
+ if len(execIDs) == 0 {
+ return nil, "", fmt.Errorf("no executions found for conversation: %s", convID)
+ }
+
+ var allEvents []*proto.ExecutionEvent
+ for _, eID := range execIDs {
+ events, err := evLog.ExecEvents(ctx, eID)
+ if err != nil {
+ return nil, "", fmt.Errorf("failed to query events for exec %s: %w", eID, err)
+ }
+ allEvents = append(allEvents, events...)
+ }
+
+ // Use the first execID as the rootExecID as requested by user
+ rootExecID := execIDs[0]
+
+ return allEvents, rootExecID, nil
}
func buildExecTraces(rootExecID string, events []*proto.ExecutionEvent) []ExecTrace {
diff --git a/docs/python-agent.md b/docs/python-agent.md
index dd81405..04da883 100644
--- a/docs/python-agent.md
+++ b/docs/python-agent.md
@@ -29,6 +29,6 @@ ax register \
ax exec \
--server localhost:8494 \
- --id exec123 \
+ --conversation d85a4b4e-c53b-4c84-b879-f10d905bce40 \
--input "Hello, can you echo what I just said?"
```
diff --git a/examples/remote_agent/main.go b/examples/remote_agent/main.go
index 29e8d51..d8fdcb4 100644
--- a/examples/remote_agent/main.go
+++ b/examples/remote_agent/main.go
@@ -26,7 +26,6 @@ import (
"google.golang.org/grpc"
"github.com/google/ax/proto"
- "github.com/google/uuid"
)
const port = ":50051"
@@ -86,8 +85,7 @@ func (s *server) Connect(stream grpc.BidiStreamingServer[proto.AgentMessage, pro
ExecId: incoming.ExecId,
Msg: &proto.AgentMessage_Outputs{
Outputs: &proto.AgentOutputs{
- Messages: []*proto.Message{responseMsg},
- CheckpointId: uuid.New().String(),
+ Messages: []*proto.Message{responseMsg},
},
},
}); err != nil {
diff --git a/internal/agent/agent.go b/internal/agent/agent.go
index 39eea67..38c2bb4 100644
--- a/internal/agent/agent.go
+++ b/internal/agent/agent.go
@@ -27,7 +27,7 @@ import (
type OutputHandler func(outgoing *proto.AgentOutputs) error
type Executor interface {
- Exec(ctx context.Context, execID string, start *proto.AgentStart, o OutputHandler) error
+ Exec(ctx context.Context, execID string, start *proto.AgentStart, o OutputHandler) (proto.State, error)
}
// Agent defines the common interface for both local and remote agents.
diff --git a/internal/agent/remote.go b/internal/agent/remote.go
index d76557a..e43530b 100644
--- a/internal/agent/remote.go
+++ b/internal/agent/remote.go
@@ -107,7 +107,7 @@ func (a *RemoteAgent) Connect(ctx context.Context, execID string, start *proto.A
switch msg := resp.Msg.(type) {
case *proto.AgentMessage_Start:
// Start a new agent call
- if err := e.Exec(stream.Context(), resp.ExecId, msg.Start, o); err != nil {
+ if _, err := e.Exec(stream.Context(), resp.ExecId, msg.Start, o); err != nil {
return fmt.Errorf("failed to execute: %w", err)
}
case *proto.AgentMessage_Outputs:
diff --git a/internal/controller/controller.go b/internal/controller/controller.go
index ee823f1..4dcda5a 100644
--- a/internal/controller/controller.go
+++ b/internal/controller/controller.go
@@ -28,8 +28,10 @@ import (
"github.com/google/ax/internal/controller/executor"
"github.com/google/ax/internal/testagent"
"github.com/google/ax/proto"
+ "github.com/google/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/types/known/anypb"
)
const plannerAgentID = "__planner"
@@ -37,11 +39,11 @@ const plannerAgentID = "__planner"
// Controller is the main controller that coordinates all components.
// It acts as a single-writer system for managing agentic loops.
type Controller struct {
- inFlightExecutionsMu sync.Mutex
- inFlightExecutions map[string]struct{}
- registry *Registry
- eventLog executor.EventLog
- plannerBuilder PlannerBuilder
+ inFlightMu sync.Mutex
+ inFlight map[string]struct{}
+ registry *Registry
+ eventLog executor.EventLog
+ plannerBuilder PlannerBuilder
}
// PlannerBuilder is a function that creates a PlanFunc given a Registry.
@@ -51,8 +53,7 @@ type PlannerBuilder func(ctx context.Context, r *Registry) (agent.Agent, error)
type Config struct {
EventLogBuilder executor.EventLogBuilder
PlannerBuilder PlannerBuilder
- // TODO(jbd): Add CompacterBuilder.
- HealthCheck config.HealthCheckConfig
+ HealthCheck config.HealthCheckConfig
}
// New creates a new controller instance.
@@ -80,26 +81,79 @@ func New(ctx context.Context, config Config) (*Controller, error) {
}
return &Controller{
- inFlightExecutions: make(map[string]struct{}),
- registry: registry,
- eventLog: eventLog,
- plannerBuilder: config.PlannerBuilder,
+ inFlight: make(map[string]struct{}),
+ registry: registry,
+ eventLog: eventLog,
+ plannerBuilder: config.PlannerBuilder,
}, nil
}
+func (d *Controller) tryResuming(ctx context.Context, req *proto.ExecRequest, el executor.EventLog, registry map[string]agent.Agent, handler agent.OutputHandler) (history []*proto.Message, done bool, err error) {
+ events, err := el.Events(ctx, req.ConversationId)
+ if err != nil {
+ return nil, false, fmt.Errorf("failed to retrieve execution history: %w", err)
+ }
+ var pendingExecID string
+ for _, ev := range events {
+ if ev.ExecId != "" && ev.State == proto.State_STATE_PENDING {
+ pendingExecID = ev.ExecId
+ }
+ if ev.ExecId == pendingExecID && ev.State == proto.State_STATE_COMPLETED {
+ pendingExecID = ""
+ }
+ history = append(history, ev.Messages...)
+ }
+
+ if pendingExecID == "" {
+ return history, false, nil
+ }
+
+ // Find the pending event.
+ execEvents, err := el.ExecEvents(ctx, pendingExecID)
+ if err != nil {
+ return nil, false, fmt.Errorf("failed to retrieve execution events: %w", err)
+ }
+
+ // TODO(jbd): Merge ExecutionEvent and ConversationEvent?
+ var pendingEvent *proto.ExecutionEvent
+ for _, ev := range execEvents {
+ if ev.State == proto.State_STATE_PENDING {
+ pendingEvent = ev
+ break
+ }
+ }
+ if pendingEvent == nil {
+ return nil, false, fmt.Errorf("failed to retrieve pending event: %w", err)
+ }
+ if err := d.execute(
+ ctx,
+ req.ConversationId,
+ pendingExecID,
+ pendingEvent.AgentId,
+ pendingEvent.AgentConfig,
+ history,
+ req.Inputs,
+ registry,
+ handler,
+ ); err != nil {
+ return nil, false, err
+ }
+ return history, true, nil
+}
+
// Exec executes a new agentic loop execution or resumes an existing one.
// If id is empty, a UUID will be generated.
// If the execution already exists, it will be resumed with optional new inputs.
-func (d *Controller) Exec(ctx context.Context, incoming *proto.AgentMessage, handler agent.OutputHandler) error {
- if incoming.ExecId == "" {
- return fmt.Errorf("id is required")
+func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler agent.OutputHandler) error {
+ if req.ConversationId == "" {
+ return fmt.Errorf("conversation_id is required")
}
- inFlight, cleanup := d.markInFlight(incoming.ExecId)
+ inFlight, cleanup := d.markInFlight(req.ConversationId)
defer cleanup()
if inFlight {
- return fmt.Errorf("execution %q is already in flight", incoming.ExecId)
+ return fmt.Errorf("execution %q is already in flight", req.ConversationId)
}
planner, err := d.plannerBuilder(ctx, d.registry)
@@ -116,26 +170,67 @@ func (d *Controller) Exec(ctx context.Context, incoming *proto.AgentMessage, han
maps.Copy(registry, testagent.Agents())
}
- start := incoming.GetStart()
- if start == nil {
- return fmt.Errorf("no start message")
+ if req.AgentId == "" {
+ req.AgentId = plannerAgentID
}
- if start.AgentId == "" {
- start.AgentId = plannerAgentID
+
+ // Replay the execution history if any.
+ history, done, err := d.tryResuming(ctx, req, d.eventLog, registry, handler)
+ if err != nil {
+ return err
}
+ if done {
+ // Nothing else to do, new inputs are used in the replay.
+ return nil
+ }
+
+ return d.execute(
+ ctx,
+ req.ConversationId,
+ uuid.NewString(),
+ req.AgentId,
+ req.AgentConfig,
+ history,
+ req.Inputs,
+ registry,
+ handler,
+ )
+}
+
+func (d *Controller) execute(ctx context.Context, conversationID string, execID string, agentID string, agentConfig *anypb.Any, history []*proto.Message, newInputs []*proto.Message, registry map[string]agent.Agent, handler agent.OutputHandler) error {
e := executor.DefaultExecutor(d.eventLog, registry)
- return e.Exec(ctx, incoming.ExecId, start, handler)
+ var outputs []*proto.Message
+ outputCapturer := func(outgoing *proto.AgentOutputs) error {
+ outputs = append(outputs, outgoing.Messages...)
+ return handler(outgoing)
+ }
+ if err := d.eventLog.Append(ctx, &proto.ConversationEvent{
+ ConversationId: conversationID,
+ ExecId: execID,
+ Messages: newInputs,
+ State: proto.State_STATE_PENDING,
+ }); err != nil {
+ return err
+ }
+ state, err := e.Exec(ctx, execID, &proto.AgentStart{
+ AgentId: agentID,
+ Config: agentConfig,
+ Messages: append(history, newInputs...),
+ }, outputCapturer)
+ if err != nil {
+ return err
+ }
+ return d.eventLog.Append(ctx, &proto.ConversationEvent{
+ ConversationId: conversationID,
+ ExecId: execID,
+ Messages: outputs,
+ State: state,
+ })
}
// Fork forks an execution from a source execution.
// If checkpointId is provided, fork til the checkpoint. Otherwise, fork the whole execution.
func (d *Controller) Fork(ctx context.Context, sourceID, sourceCheckpoint, destID string) error {
- if sourceID == "" {
- return fmt.Errorf("source ID is required")
- }
- if destID == "" {
- return fmt.Errorf("destination ID is required")
- }
return status.Errorf(codes.Unimplemented, "forking is not supported yet")
}
@@ -156,18 +251,18 @@ func (d *Controller) Close() error {
}
func (d *Controller) markInFlight(id string) (exists bool, cleanup func()) {
- d.inFlightExecutionsMu.Lock()
- defer d.inFlightExecutionsMu.Unlock()
+ d.inFlightMu.Lock()
+ defer d.inFlightMu.Unlock()
- _, ok := d.inFlightExecutions[id]
+ _, ok := d.inFlight[id]
if ok {
return true, func() {}
}
- d.inFlightExecutions[id] = struct{}{}
+ d.inFlight[id] = struct{}{}
return false, func() {
- d.inFlightExecutionsMu.Lock()
- delete(d.inFlightExecutions, id)
- d.inFlightExecutionsMu.Unlock()
+ d.inFlightMu.Lock()
+ delete(d.inFlight, id)
+ d.inFlightMu.Unlock()
}
}
diff --git a/internal/controller/controller_test.go b/internal/controller/controller_test.go
new file mode 100644
index 0000000..a83c264
--- /dev/null
+++ b/internal/controller/controller_test.go
@@ -0,0 +1,161 @@
+// 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 controller
+
+import (
+ "context"
+ "sync"
+ "testing"
+
+ "github.com/google/ax/internal/agent"
+ "github.com/google/ax/internal/controller/executor"
+ "github.com/google/ax/proto"
+)
+
+type mockEventLog struct {
+ mu sync.Mutex
+ events []*proto.ConversationEvent
+ execEvents []*proto.ExecutionEvent
+}
+
+func (m *mockEventLog) Append(ctx context.Context, event *proto.ConversationEvent) error {
+ m.events = append(m.events, event)
+ return nil
+}
+
+func (m *mockEventLog) AppendExec(ctx context.Context, event *proto.ExecutionEvent) error {
+ m.execEvents = append(m.execEvents, event)
+ return nil
+}
+
+func (m *mockEventLog) Events(ctx context.Context, conversationID string) ([]*proto.ConversationEvent, error) {
+ var out []*proto.ConversationEvent
+ for _, ev := range m.events {
+ if ev.ConversationId == conversationID {
+ out = append(out, ev)
+ }
+ }
+ return out, nil
+}
+
+func (m *mockEventLog) ExecEvents(ctx context.Context, execID string) ([]*proto.ExecutionEvent, error) {
+ var out []*proto.ExecutionEvent
+ for _, ev := range m.execEvents {
+ if ev.ExecId == execID {
+ out = append(out, ev)
+ }
+ }
+ return out, nil
+}
+
+func (m *mockEventLog) Close() error {
+ return nil
+}
+
+type dummyAgent struct{}
+
+func (a *dummyAgent) Connect(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
+ return nil
+}
+func (a *dummyAgent) HealthCheck(ctx context.Context) error { return nil }
+func (a *dummyAgent) Close() error { return nil }
+
+func TestController_Exec_ResumptionAndIDGeneration(t *testing.T) {
+ ctx := context.Background()
+ cid := "test-conv"
+
+ inputs := []*proto.Message{
+ {
+ Role: "user",
+ Content: &proto.Content{
+ Content: &proto.Content_Text{
+ Text: &proto.TextContent{Text: "hello"},
+ },
+ },
+ },
+ }
+
+ // Case 1: No history, new inputs. Should create a new execution with a UUID.
+ log := &mockEventLog{}
+ c, err := New(ctx, Config{
+ EventLogBuilder: func() (executor.EventLog, error) {
+ return log, nil
+ },
+ PlannerBuilder: func(ctx context.Context, r *Registry) (agent.Agent, error) {
+ return &dummyAgent{}, nil
+ },
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer c.Close()
+
+ err = c.Exec(ctx, &proto.ExecRequest{
+ ConversationId: cid,
+ Inputs: inputs,
+ }, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(log.events) == 0 {
+ t.Fatal("expected events to be logged")
+ }
+ execID := log.events[0].ExecId
+ if execID == "" || execID == cid {
+ t.Fatalf("expected a new random execID, got %v", execID)
+ }
+
+ // Case 2: History exists, PENDING state, inputs empty. Should replay/resume.
+ // Modify the event logged by logPending in Case 1 to use dummy-agent.
+ log.events[len(log.events)-1].State = proto.State_STATE_PENDING
+
+ err = c.Exec(ctx, &proto.ExecRequest{
+ ConversationId: cid,
+ Inputs: []*proto.Message{},
+ }, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // Replay should have called `e.Exec` for that `execID`.
+ lastEventID := log.events[len(log.events)-1].ExecId
+ if lastEventID != execID {
+ t.Fatalf("expected resumed execution ID %v, got %v", execID, lastEventID)
+ }
+
+ // Case 3: History exists, COMPLETED state, new inputs. Should create a NEW execution.
+ for _, ev := range log.execEvents {
+ if ev.ExecId == execID {
+ ev.State = proto.State_STATE_COMPLETED
+ }
+ }
+ // Also populate messages in conversation log to simulate completion.
+ log.events[len(log.events)-1].Messages = []*proto.Message{
+ {Role: "user", Content: &proto.Content{Content: &proto.Content_Text{Text: &proto.TextContent{Text: "hello"}}}},
+ }
+ log.events[len(log.events)-1].State = proto.State_STATE_COMPLETED
+
+ err = c.Exec(ctx, &proto.ExecRequest{
+ ConversationId: cid,
+ Inputs: inputs,
+ }, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ newExecID := log.events[len(log.events)-1].ExecId
+ if newExecID == execID {
+ t.Fatal("expected a NEW execution ID, but it was reused")
+ }
+}
diff --git a/internal/controller/executor/eventlog.go b/internal/controller/executor/eventlog.go
index 9fb5c17..5d9ca83 100644
--- a/internal/controller/executor/eventlog.go
+++ b/internal/controller/executor/eventlog.go
@@ -25,12 +25,17 @@ import (
// exec. Every entry is an atomic step: replaying the log in order brings
// the executor back to a consistent state from which execution can resume.
type EventLog interface {
- // Append adds an event to the end of the log.
- // Implementations must be safe for concurrent use.
- Append(ctx context.Context, event *proto.ExecutionEvent) error
+ // Append adds a conversation event to the end of the log.
+ Append(ctx context.Context, event *proto.ConversationEvent) error
- // Events returns all events recorded so far, in append order.
- Events(ctx context.Context, id string) ([]*proto.ExecutionEvent, error)
+ // AppendExec adds an execution event to the end of the log.
+ AppendExec(ctx context.Context, event *proto.ExecutionEvent) error
+
+ // Events returns all events for the conversation.
+ Events(ctx context.Context, conversationID string) ([]*proto.ConversationEvent, error)
+
+ // ExecEvents returns all events for a specific execution ID.
+ ExecEvents(ctx context.Context, execID string) ([]*proto.ExecutionEvent, error)
// Close releases the underlying resources and closes the log.
Close() error
diff --git a/internal/controller/executor/executor.go b/internal/controller/executor/executor.go
index 4886497..ffa4bed 100644
--- a/internal/controller/executor/executor.go
+++ b/internal/controller/executor/executor.go
@@ -20,6 +20,7 @@ import (
"fmt"
"github.com/google/ax/internal/agent"
+ "github.com/google/ax/internal/historyutil"
"github.com/google/ax/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -27,7 +28,7 @@ import (
type EventLogBuilder func() (EventLog, error)
type defaultExecutor struct {
- id string
+ execID string
eventLog EventLog
registry map[string]agent.Agent
}
@@ -41,30 +42,41 @@ func newExecID(parent, child string) string {
func DefaultExecutor(eventLog EventLog, registry map[string]agent.Agent) agent.Executor {
return &defaultExecutor{
- id: "",
+ execID: "",
eventLog: eventLog,
registry: registry,
}
}
-func (tm *defaultExecutor) Exec(ctx context.Context, execID string, start *proto.AgentStart, o agent.OutputHandler) error {
- execID = newExecID(tm.id, execID)
+func (tm *defaultExecutor) Exec(ctx context.Context, execID string, start *proto.AgentStart, o agent.OutputHandler) (proto.State, error) {
+ execID = newExecID(tm.execID, execID)
a, ok := tm.registry[start.AgentId]
if !ok {
- return errors.New("no agent found")
+ return proto.State_STATE_UNSPECIFIED, errors.New("no agent found")
}
allInputs, state, earlierAgentID, err := history(ctx, tm.eventLog, execID)
if err != nil {
- return err
+ return proto.State_STATE_UNSPECIFIED, err
+ }
+
+ if msg := historyutil.WaitsForConfirmation(allInputs); msg != nil {
+ // Ensure that the inputs contain the answer to the
+ // confirmation to continue.
+ _, conf := historyutil.HasConfirmationAnswer(start.Messages)
+ if conf == nil {
+ return proto.State_STATE_PENDING, o(&proto.AgentOutputs{
+ Messages: []*proto.Message{msg},
+ })
+ }
}
if earlierAgentID != "" && earlierAgentID != start.AgentId {
- return fmt.Errorf("resumption not allowed: agent ID changed from %s to %s", earlierAgentID, start.AgentId)
+ return proto.State_STATE_UNSPECIFIED, fmt.Errorf("resumption not allowed: agent ID changed from %s to %s", earlierAgentID, start.AgentId)
}
if state == proto.State_STATE_COMPLETED {
- return nil
+ return proto.State_STATE_COMPLETED, nil
}
return tm.exec(ctx, execID, start, tm.eventLog, a, allInputs, o)
}
@@ -76,9 +88,9 @@ func (tm *defaultExecutor) exec(
el EventLog,
a agent.Agent,
history []*proto.Message,
- o agent.OutputHandler) error {
+ o agent.OutputHandler) (proto.State, error) {
child := &defaultExecutor{
- id: execID,
+ execID: execID,
eventLog: tm.eventLog,
registry: tm.registry,
}
@@ -94,79 +106,77 @@ func (tm *defaultExecutor) exec(
history = append(history, start.Messages...)
if len(history) == 0 {
- return errors.New("no inputs")
+ return proto.State_STATE_UNSPECIFIED, errors.New("no inputs")
}
if err := logPending(ctx, el, execID, start); err != nil {
- return err
+ return proto.State_STATE_UNSPECIFIED, err
}
start.Messages = history
if err := a.Connect(ctx, execID, start, child, outputBuffer); err != nil {
- _ = logFailed(ctx, el, execID, start) // Attempt to log failure, but prioritize returning the original error.
- return err
+ // _ = logFailed(ctx, el, execID, start) // Attempt to log failure, but prioritize returning the original error.
+ return proto.State_STATE_UNSPECIFIED, err
}
if len(allOutputs) > 0 {
// Log all the outputs at once.
// TODO: Log only at checkpoints.
if err := logOutputs(ctx, el, execID, start, allOutputs); err != nil {
- return err
+ return proto.State_STATE_UNSPECIFIED, err
}
last := allOutputs[len(allOutputs)-1]
if last.GetContent().GetConfirmation() == nil || last.GetContent().GetConfirmation().GetQuestion() == "" {
// Log completed only if we are not waiting
// for an answer to a confirmation.
- return logCompleted(ctx, el, execID, start)
+ if err := logCompleted(ctx, el, execID, start); err != nil {
+ return proto.State_STATE_UNSPECIFIED, err
+ }
+ return proto.State_STATE_COMPLETED, nil
}
}
- return nil
+ return proto.State_STATE_PENDING, nil
}
func history(ctx context.Context, el EventLog, execID string) ([]*proto.Message, proto.State, string, error) {
- events, err := el.Events(ctx, execID)
- if err != nil {
- return nil, proto.State_STATE_UNSPECIFIED, "", err
- }
-
var history []*proto.Message
+
var state proto.State
var agentID string
- for _, event := range events {
- if event.ExecId != execID {
- continue
- }
- if event.AgentId != "" {
- agentID = event.AgentId
+ if execID != "" {
+ execEvents, err := el.ExecEvents(ctx, execID)
+ if err != nil {
+ return nil, proto.State_STATE_UNSPECIFIED, "", err
}
- // Reset after the status change ensure
- // that we have a clean state even if we are
- // presented an event log with dirty entries
- // from previous runs.
- if event.State == proto.State_STATE_PENDING {
- history = []*proto.Message{}
+ for _, ev := range execEvents {
+ if ev.State != proto.State_STATE_UNSPECIFIED {
+ state = ev.State
+ }
+ if ev.AgentId != "" {
+ agentID = ev.AgentId
+ }
+ history = append(history, ev.Inputs...)
+ history = append(history, ev.Outputs...)
}
- history = append(history, event.Inputs...)
- history = append(history, event.Outputs...)
- state = event.State
}
return history, state, agentID, nil
}
func logPending(ctx context.Context, el EventLog, execID string, start *proto.AgentStart) error {
- return el.Append(ctx, &proto.ExecutionEvent{
- Timestamp: timestamppb.Now(),
- ExecId: execID,
- AgentId: start.AgentId,
- Inputs: start.Messages,
- State: proto.State_STATE_PENDING,
+ return el.AppendExec(ctx, &proto.ExecutionEvent{
+ Timestamp: timestamppb.Now(),
+ ExecId: execID,
+ AgentId: start.AgentId,
+ AgentConfig: start.Config,
+ Inputs: start.Messages,
+ State: proto.State_STATE_PENDING,
})
}
func logFailed(ctx context.Context, el EventLog, execID string, start *proto.AgentStart) error {
- return el.Append(ctx, &proto.ExecutionEvent{
+ return el.AppendExec(ctx, &proto.ExecutionEvent{
Timestamp: timestamppb.Now(),
ExecId: execID,
AgentId: start.AgentId,
@@ -175,7 +185,7 @@ func logFailed(ctx context.Context, el EventLog, execID string, start *proto.Age
}
func logCompleted(ctx context.Context, el EventLog, execID string, start *proto.AgentStart) error {
- return el.Append(ctx, &proto.ExecutionEvent{
+ return el.AppendExec(ctx, &proto.ExecutionEvent{
Timestamp: timestamppb.Now(),
ExecId: execID,
AgentId: start.AgentId,
@@ -184,10 +194,11 @@ func logCompleted(ctx context.Context, el EventLog, execID string, start *proto.
}
func logOutputs(ctx context.Context, el EventLog, execID string, start *proto.AgentStart, outputs []*proto.Message) error {
- return el.Append(ctx, &proto.ExecutionEvent{
+ return el.AppendExec(ctx, &proto.ExecutionEvent{
Timestamp: timestamppb.Now(),
ExecId: execID,
AgentId: start.AgentId,
Outputs: outputs,
+ State: proto.State_STATE_PENDING,
})
}
diff --git a/internal/controller/executor/executor_test.go b/internal/controller/executor/executor_test.go
index 71f9c34..a783563 100644
--- a/internal/controller/executor/executor_test.go
+++ b/internal/controller/executor/executor_test.go
@@ -25,6 +25,7 @@ import (
"time"
"github.com/google/ax/internal/agent"
+ "github.com/google/ax/internal/historyutil"
"github.com/google/ax/proto"
"golang.org/x/sync/errgroup"
)
@@ -32,11 +33,12 @@ import (
// MemoryEventLog is an in-memory EventLog useful for testing and short-lived
// executions. It does not survive process restarts.
type MemoryEventLog struct {
- mu sync.Mutex
- events []*proto.ExecutionEvent
+ mu sync.Mutex
+ events []*proto.ConversationEvent
+ execEvents []*proto.ExecutionEvent
}
-func (m *MemoryEventLog) Append(_ context.Context, event *proto.ExecutionEvent) error {
+func (m *MemoryEventLog) Append(_ context.Context, event *proto.ConversationEvent) error {
m.mu.Lock()
defer m.mu.Unlock()
@@ -44,12 +46,33 @@ func (m *MemoryEventLog) Append(_ context.Context, event *proto.ExecutionEvent)
return nil
}
-func (m *MemoryEventLog) Events(_ context.Context, execID string) ([]*proto.ExecutionEvent, error) {
+func (m *MemoryEventLog) AppendExec(_ context.Context, event *proto.ExecutionEvent) error {
m.mu.Lock()
defer m.mu.Unlock()
- out := make([]*proto.ExecutionEvent, 0)
+ m.execEvents = append(m.execEvents, event)
+ return nil
+}
+
+func (m *MemoryEventLog) Events(_ context.Context, conversationID string) ([]*proto.ConversationEvent, error) {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+
+ out := make([]*proto.ConversationEvent, 0)
for _, ev := range m.events {
+ if ev.ConversationId == conversationID {
+ out = append(out, ev)
+ }
+ }
+ return out, nil
+}
+
+func (m *MemoryEventLog) ExecEvents(_ context.Context, execID string) ([]*proto.ExecutionEvent, error) {
+ m.mu.Lock()
+ defer m.mu.Unlock()
+
+ out := make([]*proto.ExecutionEvent, 0)
+ for _, ev := range m.execEvents {
if ev.ExecId == execID {
out = append(out, ev)
}
@@ -59,7 +82,7 @@ func (m *MemoryEventLog) Events(_ context.Context, execID string) ([]*proto.Exec
// Drop removes every event for which drop returns true.
// It is provided for testing and crash-simulation purposes.
-func (m *MemoryEventLog) Drop(drop func(*proto.ExecutionEvent) bool) {
+func (m *MemoryEventLog) Drop(drop func(*proto.ConversationEvent) bool) {
m.mu.Lock()
defer m.mu.Unlock()
@@ -86,14 +109,14 @@ func Example() {
registry := map[string]agent.Agent{
"planner": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
- if err := tm.Exec(ctx, "deep-research-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "deep-research-task", &proto.AgentStart{
AgentId: "deep-research",
Messages: inputs,
}, o); err != nil {
return
}
- if err := tm.Exec(ctx, "pub-med-lookup-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "pub-med-lookup-task", &proto.AgentStart{
AgentId: "pub-med-index",
Messages: inputs,
}, o); err != nil {
@@ -103,7 +126,7 @@ func Example() {
}
tm := DefaultExecutor(memoryEventLog(), registry)
- if err := tm.Exec(ctx, "test", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "test", &proto.AgentStart{
AgentId: "planner",
Messages: []*proto.Message{text("user", "Hello, I'd like to research cancer treatment options.")},
}, nil); err != nil {
@@ -116,7 +139,7 @@ func TestTaskManager(t *testing.T) {
registry := map[string]agent.Agent{
"root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
- if err := tm.Exec(ctx, "child-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "child-task", &proto.AgentStart{
AgentId: "child",
Messages: inputs,
}, o); err != nil {
@@ -139,7 +162,7 @@ func TestTaskManager(t *testing.T) {
}
tm := DefaultExecutor(memoryEventLog(), registry)
- if err := tm.Exec(ctx, "root-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "root-task", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{text("user", "hello!")},
}, nil); err != nil {
@@ -157,10 +180,11 @@ func TestFanout(t *testing.T) {
for i := range 50 {
i := i // Capture loop variable.
g.Go(func() error {
- return tm.Exec(ctx, fmt.Sprintf("child-%d", i), &proto.AgentStart{
+ _, err := tm.Exec(ctx, fmt.Sprintf("child-%d", i), &proto.AgentStart{
AgentId: "child",
Messages: inputs,
}, nil)
+ return err
})
}
if err := g.Wait(); err != nil {
@@ -180,10 +204,11 @@ func TestFanout(t *testing.T) {
for i := range 2 {
i := i // Capture loop variable.
g.Go(func() error {
- return tm.Exec(ctx, fmt.Sprintf("child2-%d", i), &proto.AgentStart{
+ _, err := tm.Exec(ctx, fmt.Sprintf("child2-%d", i), &proto.AgentStart{
AgentId: "child2",
Messages: inputs,
}, nil)
+ return err
})
}
if err := g.Wait(); err != nil {
@@ -207,7 +232,7 @@ func TestFanout(t *testing.T) {
}
tm := DefaultExecutor(memoryEventLog(), registry)
- if err := tm.Exec(ctx, "root-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "root-task", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{text("user", "hello!")},
}, nil); err != nil {
@@ -229,7 +254,7 @@ func TestConfirmation(t *testing.T) {
var childDone atomic.Bool
registry := map[string]agent.Agent{
"root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
- if err := tm.Exec(ctx, "child-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "child-task", &proto.AgentStart{
AgentId: "child",
Messages: inputs,
}, o); err != nil {
@@ -272,7 +297,7 @@ func TestConfirmation(t *testing.T) {
tm := DefaultExecutor(eventLog, registry)
// First run: child returns a confirmation request.
- if err := tm.Exec(ctx, "root-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "root-task", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{text("user", "hello!")},
}, nil); err != nil {
@@ -293,7 +318,7 @@ func TestConfirmation(t *testing.T) {
},
},
}
- if err := tm.Exec(ctx, "root-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "root-task", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{approval},
}, nil); err != nil {
@@ -311,7 +336,7 @@ func TestResume(t *testing.T) {
registry := map[string]agent.Agent{
"root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
- if err := tm.Exec(ctx, "child-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "child-task", &proto.AgentStart{
AgentId: "child",
Messages: inputs,
}, nil); err != nil {
@@ -334,7 +359,7 @@ func TestResume(t *testing.T) {
}
tm := DefaultExecutor(eventLog, registry)
- if err := tm.Exec(ctx, "root-task", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "root-task", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{text("user", "hello!")},
}, nil); err != nil {
@@ -357,7 +382,7 @@ func TestResumeAgentIDMismatch(t *testing.T) {
tm := DefaultExecutor(eventLog, registry)
// First run: starts as "root"
- if err := tm.Exec(ctx, "task1", &proto.AgentStart{
+ if _, err := tm.Exec(ctx, "task1", &proto.AgentStart{
AgentId: "root",
Messages: []*proto.Message{text("user", "hello!")},
}, nil); err != nil {
@@ -365,7 +390,7 @@ func TestResumeAgentIDMismatch(t *testing.T) {
}
// Second run: attempts to resume as "other" for same execID "task1"
- err := tm.Exec(ctx, "task1", &proto.AgentStart{
+ _, err := tm.Exec(ctx, "task1", &proto.AgentStart{
AgentId: "other",
Messages: []*proto.Message{text("user", "hello again!")},
}, nil)
@@ -378,3 +403,121 @@ func TestResumeAgentIDMismatch(t *testing.T) {
t.Fatalf("expected 'resumption not allowed' error, got: %v", err)
}
}
+
+func TestResumeConfirmation(t *testing.T) {
+ ctx := context.Background()
+ eventLog := memoryEventLog()
+
+ msg := &proto.Message{
+ Content: &proto.Content{
+ Content: &proto.Content_Confirmation{
+ Confirmation: &proto.ConfirmationContent{
+ Id: "test-conf-id",
+ Question: "proceed?",
+ },
+ },
+ },
+ }
+
+ var runCount int
+ registry := map[string]agent.Agent{
+ "root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
+ if conf := historyutil.WaitsForConfirmation(inputs); conf != nil {
+ o(&proto.AgentOutputs{
+ Messages: []*proto.Message{msg},
+ })
+ return
+ }
+
+ approved, _ := historyutil.HasConfirmationAnswer(inputs)
+ if approved {
+ if err := o(&proto.AgentOutputs{
+ // "Hello!" is responded with a confirmation request.
+ Messages: []*proto.Message{{
+ Content: &proto.Content{
+ Content: &proto.Content_Text{
+ Text: &proto.TextContent{
+ Text: "awesome!",
+ },
+ },
+ },
+ }},
+ }); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if runCount == 0 {
+ runCount++
+ if err := o(&proto.AgentOutputs{
+ // "Hello!" is responded with a confirmation request.
+ Messages: []*proto.Message{msg},
+ }); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }),
+ }
+
+ tm := DefaultExecutor(eventLog, registry)
+
+ // First run: starts as "root"
+ if _, err := tm.Exec(ctx, "task1", &proto.AgentStart{
+ AgentId: "root",
+ Messages: []*proto.Message{text("user", "hello!")},
+ }, nil); err != nil {
+ t.Fatal(err)
+ }
+
+ var confirmation *proto.ConfirmationContent
+ handler := func(outputs *proto.AgentOutputs) error {
+ confirmation = outputs.Messages[0].GetContent().GetConfirmation()
+ return nil
+ }
+ // Second run: attempts to resume as "other" for same execID "task1"
+ if _, err := tm.Exec(ctx, "task1", &proto.AgentStart{
+ AgentId: "root",
+ }, handler); err != nil {
+ t.Fatal(err)
+ }
+ if confirmation == nil {
+ t.Fatal("confirmation is nil")
+ }
+ if confirmation.Id != "test-conf-id" {
+ t.Fatalf("confirmation id mismatch: got %v, want %v", confirmation.Id, "test-conf-id")
+ }
+
+ // Third run: user provides an approval decision.
+ var msgs []*proto.Message
+ handler = func(outputs *proto.AgentOutputs) error {
+ msgs = outputs.Messages
+ return nil
+ }
+ if _, err := tm.Exec(ctx, "task1", &proto.AgentStart{
+ AgentId: "root",
+ Messages: []*proto.Message{
+ {
+ Content: &proto.Content{
+ Content: &proto.Content_Confirmation{
+ Confirmation: &proto.ConfirmationContent{
+ Id: "test-conf-id",
+ Decision: &proto.ConfirmationContent_Approval{
+ Approval: &proto.ApprovalDecision{
+ Approved: true,
+ },
+ },
+ },
+ },
+ },
+ },
+ }}, handler); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(msgs) != 1 {
+ t.Fatalf("expected 1 message, got %v", len(msgs))
+ }
+ if msgs[0].GetContent().GetText().GetText() != "awesome!" {
+ t.Fatalf("expected 'awesome!', got %v", msgs[0].GetContent().GetText().GetText())
+ }
+}
diff --git a/internal/controller/executor/sqlite.go b/internal/controller/executor/sqlite.go
index 0c52b10..580b435 100644
--- a/internal/controller/executor/sqlite.go
+++ b/internal/controller/executor/sqlite.go
@@ -17,9 +17,11 @@ package executor
import (
"context"
"database/sql"
+ "encoding/json"
"fmt"
"os"
"path/filepath"
+ "strings"
"time"
"github.com/google/ax/proto"
@@ -47,95 +49,158 @@ func OpenSQLiteEventLog(path string) (*SQLiteEventLog, error) {
return nil, fmt.Errorf("sqlite_eventlog: open %s: %w", dsn, err)
}
- // Create table if it doesn't exist
+ // Create tables if they don't exist
if _, err := db.Exec(`
- CREATE TABLE IF NOT EXISTS event_log (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
+ CREATE TABLE IF NOT EXISTS conversation_log (
+ conversation_id TEXT NOT NULL,
+ seq INTEGER NOT NULL,
exec_id TEXT NOT NULL,
- checkpoint_id TEXT,
- state INTEGER NOT NULL,
- payload TEXT NOT NULL,
- timestamp DATETIME NOT NULL
+ messages TEXT,
+ state INTEGER,
+ PRIMARY KEY (conversation_id, seq)
)`); err != nil {
db.Close()
- return nil, fmt.Errorf("sqlite_eventlog: create table: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: create conversation_log table: %w", err)
}
- // Create index if it doesn't exist
- if _, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_event_log_exec_id ON event_log(exec_id)`); err != nil {
+ if _, err := db.Exec(`
+ CREATE TABLE IF NOT EXISTS execution_log (
+ exec_id TEXT NOT NULL,
+ payload TEXT NOT NULL,
+ timestamp DATETIME NOT NULL
+ )`); err != nil {
db.Close()
- return nil, fmt.Errorf("sqlite_eventlog: create index exec_id: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: create execution_log table: %w", err)
}
- if _, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_event_log_exec_checkpoint_id ON event_log(exec_id, checkpoint_id)`); err != nil {
+ // Create indexes if they don't exist
+ if _, err := db.Exec(`CREATE INDEX IF NOT EXISTS idx_execution_log_exec_id ON execution_log(exec_id)`); err != nil {
db.Close()
- return nil, fmt.Errorf("sqlite_eventlog: create index exec_checkpoint_id: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: create index exec_id: %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 {
+func (l *SQLiteEventLog) Append(ctx context.Context, event *proto.ConversationEvent) error {
+ seq := event.Seq
+ if seq == 0 {
+ err := l.db.QueryRowContext(ctx, "SELECT COALESCE(MAX(seq), 0) + 1 FROM conversation_log WHERE conversation_id = ?", event.ConversationId).Scan(&seq)
+ if err != nil {
+ return fmt.Errorf("sqlite_eventlog: compute seq: %w", err)
+ }
+ event.Seq = seq
+ }
+
+ var messagesJSON string
+ if len(event.Messages) > 0 {
+ var sb strings.Builder
+ sb.WriteString("[")
+ for i, m := range event.Messages {
+ if i > 0 {
+ sb.WriteString(",")
+ }
+ payload, err := marshalOpts.Marshal(m)
+ if err != nil {
+ return fmt.Errorf("sqlite_eventlog: marshal message: %w", err)
+ }
+ sb.Write(payload)
+ }
+ sb.WriteString("]")
+ messagesJSON = sb.String()
+ }
+
+ _, err := l.db.ExecContext(ctx,
+ "INSERT INTO conversation_log (conversation_id, seq, exec_id, messages, state) VALUES (?, ?, ?, ?, ?)",
+ event.ConversationId, event.Seq, event.ExecId, messagesJSON, int32(event.State))
+
+ if err != nil {
+ return fmt.Errorf("sqlite_eventlog: insert conversation: %w", err)
+ }
+
+ return nil
+}
+
+// AppendExec inserts an execution event into the database.
+func (l *SQLiteEventLog) AppendExec(ctx context.Context, event *proto.ExecutionEvent) error {
payload, err := marshalOpts.Marshal(event)
if err != nil {
- return fmt.Errorf("sqlite_eventlog: marshal: %w", err)
+ return fmt.Errorf("sqlite_eventlog: marshal exec: %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 (exec_id, checkpoint_id, state, payload, timestamp) VALUES (?, ?, ?, ?, ?)",
- event.ExecId, event.CheckpointId, event.State, string(payload), timestamp)
+ "INSERT INTO execution_log (exec_id, payload, timestamp) VALUES (?, ?, ?)",
+ event.ExecId, string(payload), timestamp)
if err != nil {
- return fmt.Errorf("sqlite_eventlog: insert: %w", err)
+ return fmt.Errorf("sqlite_eventlog: insert exec: %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 exec_id = ?", id)
+// Events retrieves all events from the database for a conversation, ordered by seq and execution order.
+func (l *SQLiteEventLog) Events(ctx context.Context, conversationID string) ([]*proto.ConversationEvent, error) {
+ rows, err := l.db.QueryContext(ctx, "SELECT seq, exec_id, messages, state FROM conversation_log WHERE conversation_id = ? ORDER BY seq", conversationID)
if err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: query: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: query conversation: %w", err)
}
defer rows.Close()
- var events []*proto.ExecutionEvent
+ var events []*proto.ConversationEvent
for rows.Next() {
- var payload string
- if err := rows.Scan(&payload); err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: scan: %w", err)
+ var seq int32
+ var execID string
+ var messagesJSON sql.NullString
+ var state int32
+ if err := rows.Scan(&seq, &execID, &messagesJSON, &state); err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: scan conversation: %w", err)
}
- ev := &proto.ExecutionEvent{}
- if err := unmarshalOpts.Unmarshal([]byte(payload), ev); err != nil {
- // Similar to FileEventLog, skip lines that cannot be decoded.
- continue
+ var messages []*proto.Message
+ if messagesJSON.Valid && messagesJSON.String != "" {
+ var rawMessages []json.RawMessage
+ if err := json.Unmarshal([]byte(messagesJSON.String), &rawMessages); err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: unmarshal raw messages: %w", err)
+ }
+ for _, raw := range rawMessages {
+ m := &proto.Message{}
+ if err := unmarshalOpts.Unmarshal(raw, m); err != nil {
+ return nil, fmt.Errorf("sqlite_eventlog: unmarshal proto message: %w", err)
+ }
+ messages = append(messages, m)
+ }
}
- events = append(events, ev)
+
+ events = append(events, &proto.ConversationEvent{
+ ConversationId: conversationID,
+ Seq: seq,
+ ExecId: execID,
+ Messages: messages,
+ State: proto.State(state),
+ })
}
if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: iterate: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: iterate conversation: %w", err)
}
return events, nil
}
-// EventsByPrefix retrieves all events from the database matching a exec_id prefix, ordered by insertion order.
-func (l *SQLiteEventLog) EventsByPrefix(ctx context.Context, prefix string) ([]*proto.ExecutionEvent, error) {
- rows, err := l.db.QueryContext(ctx, "SELECT payload FROM event_log WHERE exec_id LIKE ? ORDER BY id", prefix+"%")
+// ExecEvents retrieves all events from the database for a specific execution ID.
+func (l *SQLiteEventLog) ExecEvents(ctx context.Context, execID string) ([]*proto.ExecutionEvent, error) {
+ rows, err := l.db.QueryContext(ctx, "SELECT payload FROM execution_log WHERE exec_id = ? ORDER BY timestamp", execID)
if err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: query: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: query exec: %w", err)
}
defer rows.Close()
@@ -143,7 +208,7 @@ func (l *SQLiteEventLog) EventsByPrefix(ctx context.Context, prefix string) ([]*
for rows.Next() {
var payload string
if err := rows.Scan(&payload); err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: scan: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: scan exec: %w", err)
}
ev := &proto.ExecutionEvent{}
@@ -154,7 +219,7 @@ func (l *SQLiteEventLog) EventsByPrefix(ctx context.Context, prefix string) ([]*
}
if err := rows.Err(); err != nil {
- return nil, fmt.Errorf("sqlite_eventlog: iterate: %w", err)
+ return nil, fmt.Errorf("sqlite_eventlog: iterate exec: %w", err)
}
return events, nil
diff --git a/internal/controller/executor/sqlite_test.go b/internal/controller/executor/sqlite_test.go
index 770af2b..5b28031 100644
--- a/internal/controller/executor/sqlite_test.go
+++ b/internal/controller/executor/sqlite_test.go
@@ -35,7 +35,41 @@ func TestSQLiteEventLog_AppendAndEvents(t *testing.T) {
}
defer log.Close()
- ev1 := &proto.ExecutionEvent{
+ // 1. Test Conversation Log
+ cev1 := &proto.ConversationEvent{
+ ConversationId: "conv-1",
+ Seq: 1,
+ ExecId: "task-1",
+ }
+
+ cev2 := &proto.ConversationEvent{
+ ConversationId: "conv-1",
+ Seq: 2,
+ ExecId: "task-2",
+ }
+
+ if err := log.Append(ctx, cev1); err != nil {
+ t.Fatalf("failed to append cev1: %v", err)
+ }
+ if err := log.Append(ctx, cev2); err != nil {
+ t.Fatalf("failed to append cev2: %v", err)
+ }
+
+ cEvents, err := log.Events(ctx, "conv-1")
+ if err != nil {
+ t.Fatalf("failed to read conversation events: %v", err)
+ }
+
+ if len(cEvents) != 2 {
+ t.Fatalf("expected 2 conversation events, got %d", len(cEvents))
+ }
+
+ if cEvents[0].ExecId != "task-1" || cEvents[1].ExecId != "task-2" {
+ t.Errorf("conversation events mismatch")
+ }
+
+ // 2. Test Execution Log
+ ee1 := &proto.ExecutionEvent{
ExecId: "task-1",
State: proto.State_STATE_PENDING,
Timestamp: timestamppb.Now(),
@@ -44,36 +78,21 @@ func TestSQLiteEventLog_AppendAndEvents(t *testing.T) {
},
}
- ev2 := &proto.ExecutionEvent{
- ExecId: "task-1",
- State: proto.State_STATE_COMPLETED,
- Timestamp: timestamppb.Now(),
- Outputs: []*proto.Message{
- {Role: "assistant", Content: &proto.Content{Content: &proto.Content_Text{Text: &proto.TextContent{Text: "world"}}}},
- },
+ if err := log.AppendExec(ctx, ee1); err != nil {
+ t.Fatalf("failed to append ee1: %v", err)
}
- 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")
+ eEvents, err := log.ExecEvents(ctx, "task-1")
if err != nil {
- t.Fatalf("failed to read events: %v", err)
+ t.Fatalf("failed to read execution events: %v", err)
}
- if len(events) != 2 {
- t.Fatalf("expected 2 events, got %d", len(events))
+ if len(eEvents) != 1 {
+ t.Fatalf("expected 1 execution event, got %d", len(eEvents))
}
- if events[0].ExecId != "task-1" || events[0].State != proto.State_STATE_PENDING {
- t.Errorf("ev1 metadata mismatch")
- }
- if events[1].ExecId != "task-1" || events[1].State != proto.State_STATE_COMPLETED {
- t.Errorf("ev2 metadata mismatch")
+ if eEvents[0].ExecId != "task-1" || eEvents[0].State != proto.State_STATE_PENDING {
+ t.Errorf("execution event mismatch")
}
}
@@ -95,11 +114,11 @@ func TestSQLiteEventLog_ConcurrentAppend(t *testing.T) {
wg.Add(1)
go func(agentIdx int) {
defer wg.Done()
- for range numEvents {
- ev := &proto.ExecutionEvent{
- ExecId: "task-concurrent",
- State: proto.State(agentIdx % 4), // distribute states 0-3
- Timestamp: timestamppb.Now(),
+ for i := range numEvents {
+ ev := &proto.ConversationEvent{
+ ConversationId: "conv-concurrent",
+ Seq: int32(agentIdx*numEvents + i + 1),
+ ExecId: "task-concurrent",
}
if err := log.Append(ctx, ev); err != nil {
t.Errorf("concurrent append failed: %v", err)
@@ -110,7 +129,7 @@ func TestSQLiteEventLog_ConcurrentAppend(t *testing.T) {
wg.Wait()
- events, err := log.Events(ctx, "task-concurrent")
+ events, err := log.Events(ctx, "conv-concurrent")
if err != nil {
t.Fatalf("failed to read events: %v", err)
}
@@ -130,7 +149,7 @@ func TestSQLiteEventLog_Empty(t *testing.T) {
}
defer log.Close()
- events, err := log.Events(ctx, "task-1")
+ events, err := log.Events(ctx, "conv-1")
if err != nil {
t.Fatalf("failed to read events: %v", err)
}
diff --git a/internal/controller/gemini_planner.go b/internal/controller/gemini_planner.go
index d48f963..f0e0ce1 100644
--- a/internal/controller/gemini_planner.go
+++ b/internal/controller/gemini_planner.go
@@ -148,7 +148,7 @@ func (p *geminiPlannerAgent) loop(ctx context.Context, start *proto.AgentStart,
Messages: append(start.Messages, outputs...),
}
outputs = nil
- if err := e.Exec(ctx, nextAgentID, start, handler); err != nil {
+ if _, err := e.Exec(ctx, nextAgentID, start, handler); err != nil {
return err
}
}
@@ -350,14 +350,7 @@ func protoToContents(inputs []*proto.Message) []*genai.Content {
},
})
case *proto.Content_Confirmation:
- if m.Confirmation.Question != "" {
- contents = append(contents, &genai.Content{
- Role: "model",
- Parts: []*genai.Part{
- {Text: m.Confirmation.Question},
- },
- })
- }
+ // shouldn't be sent to Gemini
switch m.Confirmation.Decision.(type) {
case *proto.ConfirmationContent_Decline:
// shouldn't be sent to Gemini
diff --git a/internal/controller/registry_test.go b/internal/controller/registry_test.go
index cbdc062..e3e9ee1 100644
--- a/internal/controller/registry_test.go
+++ b/internal/controller/registry_test.go
@@ -27,36 +27,11 @@ import (
"github.com/google/ax/internal/agent"
"github.com/google/ax/internal/config"
+ "github.com/google/ax/internal/controller/executor"
"github.com/google/ax/proto"
)
-// MockAgent is a mock implementation of the Agent interface for testing.
-type MockAgent struct {
- ProcessFunc func(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error
- healthCheckFunc func(ctx context.Context) error
- closeFunc func() error
-}
-func (m *MockAgent) Connect(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {
- if m.ProcessFunc != nil {
- return m.ProcessFunc(ctx, execID, start, e, o)
- }
- return nil
-}
-
-func (m *MockAgent) HealthCheck(ctx context.Context) error {
- if m.healthCheckFunc != nil {
- return m.healthCheckFunc(ctx)
- }
- return nil
-}
-
-func (m *MockAgent) Close() error {
- if m.closeFunc != nil {
- return m.closeFunc()
- }
- return nil
-}
type mockAgentServer struct {
proto.UnimplementedAgentServiceServer
@@ -138,11 +113,11 @@ func TestRegistry_HealthCheckScenarios(t *testing.T) {
if tt.agentType == "local" {
// Mock local agent
- validMockAgent := &MockAgent{}
+ agent := executor.AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {})
err = r.RegisterLocal(config.LocalAgentConfig{
ID: id,
Name: id,
- Agent: validMockAgent,
+ Agent: agent,
})
if err != nil {
t.Fatalf("RegisterLocal failed: %v", err)
diff --git a/internal/historyutil/confirmations.go b/internal/historyutil/confirmations.go
index c3759d2..6573000 100644
--- a/internal/historyutil/confirmations.go
+++ b/internal/historyutil/confirmations.go
@@ -18,15 +18,15 @@ import "github.com/google/ax/proto"
// WaitsForConfirmation returns true if the last message in the history
// is a confirmation question waiting for user input.
-func WaitsForConfirmation(history []*proto.Message) bool {
+func WaitsForConfirmation(history []*proto.Message) *proto.Message {
if len(history) == 0 {
- return false
+ return nil
}
last := history[len(history)-1]
if last.GetContent().GetConfirmation() != nil && last.GetContent().GetConfirmation().Question != "" {
- return true
+ return last
}
- return false
+ return nil
}
// HasConfirmationAnswer returns true if the last message in the history
@@ -50,17 +50,17 @@ func HasConfirmationAnswer(history []*proto.Message) (approved bool, conf *proto
return approved, conf
}
-func WaitsForUser(history []*proto.Message) bool {
+func WaitsForUser(history []*proto.Message) *proto.Message {
if len(history) == 0 {
- return false
+ return nil
}
- if WaitsForConfirmation(history) {
- return true
+ if msg := WaitsForConfirmation(history); msg != nil {
+ return msg
}
last := history[len(history)-1]
if last.GetContent().GetConfirmation() != nil && last.GetContent().GetConfirmation().GetDecline() != nil {
- return true
+ return last
}
- return false
+ return nil
}
diff --git a/internal/server/server.go b/internal/server/server.go
index 98d268e..f23eaa2 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -23,6 +23,8 @@ import (
"net"
"google.golang.org/grpc"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
"github.com/google/ax/internal/agent"
"github.com/google/ax/internal/config"
@@ -53,26 +55,11 @@ func (s *Server) Exec(req *proto.ExecRequest, stream grpc.ServerStreamingServer[
Outputs: outgoing.Messages,
})
})
- return s.controller.Exec(stream.Context(), &proto.AgentMessage{
- ExecId: req.Id,
- Msg: &proto.AgentMessage_Start{
- Start: &proto.AgentStart{
- AgentId: req.AgentId,
- Config: req.AgentConfig,
- Messages: req.Inputs,
- },
- },
- }, outputHandler)
+ return s.controller.Exec(stream.Context(), req, outputHandler)
}
func (s *Server) Fork(ctx context.Context, req *proto.ForkRequest) (*proto.ForkResponse, error) {
- if err := s.controller.Fork(ctx, req.SrcId, req.SrcCheckpointId, req.DestId); err != nil {
- return nil, err
- }
-
- return &proto.ForkResponse{
- NewId: req.DestId,
- }, nil
+ return nil, status.Errorf(codes.Unimplemented, "forking not implemented")
}
// RegisterAgent registers a new remote agent with the controller.
@@ -98,7 +85,7 @@ func (s *Server) RegisterAgent(ctx context.Context, req *proto.RegisterAgentRequ
if cfg.Remote.Address == "" {
return nil, fmt.Errorf("address is required for remote agents")
}
-
+
var err error
healthy, err = registry.RegisterRemote(config.RemoteAgentConfig{
ID: req.AgentId,
diff --git a/internal/test_multi/test_multi.go b/internal/test_multi/test_multi.go
index 61b4af9..036aa02 100644
--- a/internal/test_multi/test_multi.go
+++ b/internal/test_multi/test_multi.go
@@ -18,11 +18,14 @@ import (
"context"
"fmt"
"log"
+ "os"
+ "path/filepath"
"strings"
"github.com/google/ax/internal/agent"
"github.com/google/ax/internal/config"
"github.com/google/ax/internal/controller"
+ "github.com/google/ax/internal/controller/executor"
"github.com/google/ax/proto"
"github.com/google/uuid"
)
@@ -43,6 +46,9 @@ func main() {
HealthCheck: config.HealthCheckConfig{
Enabled: false, // disable to speed up
},
+ EventLogBuilder: func() (executor.EventLog, error) {
+ return executor.OpenSQLiteEventLog(filepath.Join(os.TempDir(), "test_multi.db"))
+ },
PlannerBuilder: func(ctx context.Context, r *controller.Registry) (agent.Agent, error) {
return &mockPlanner{}, nil
},
@@ -106,31 +112,15 @@ func main() {
return nil
})
- req := &proto.AgentMessage{
- ExecId: execID,
- Msg: &proto.AgentMessage_Start{
- Start: &proto.AgentStart{
- AgentId: "planner",
- Messages: inputs,
- },
- },
- }
-
for i := range 4 {
log.Printf("\n--- Executing step %d ---\n", i+1)
- if err := c.Exec(ctx, req, handler); err != nil {
+ if err := c.Exec(ctx, &proto.ExecRequest{
+ ConversationId: execID,
+ AgentId: "planner",
+ Inputs: inputs,
+ }, handler); err != nil {
log.Fatalf("Error executing step %d: %v\n", i+1, err)
}
- // Subsequent execs just ask the planner to continue processing the existing history
- req = &proto.AgentMessage{
- ExecId: execID,
- Msg: &proto.AgentMessage_Start{
- Start: &proto.AgentStart{
- AgentId: "planner",
- Messages: inputs,
- },
- },
- }
}
}
@@ -195,10 +185,11 @@ func (m *mockPlanner) Connect(ctx context.Context, execID string, start *proto.A
},
},
})
- return e.Exec(ctx, "local-echo", &proto.AgentStart{
+ _, err := e.Exec(ctx, "local-echo", &proto.AgentStart{
AgentId: "local-echo-agent",
Messages: inputs,
}, handler)
+ return err
}
// Step 2: Local -> Remote
@@ -211,10 +202,11 @@ func (m *mockPlanner) Connect(ctx context.Context, execID string, start *proto.A
},
},
})
- return e.Exec(ctx, "remote-text", &proto.AgentStart{
+ _, err := e.Exec(ctx, "remote-text", &proto.AgentStart{
AgentId: "remote-text-processor",
Messages: inputs,
}, handler)
+ return err
}
// Step 3: Remote -> Sandbox
@@ -227,10 +219,11 @@ func (m *mockPlanner) Connect(ctx context.Context, execID string, start *proto.A
},
},
})
- return e.Exec(ctx, "uppercase-task", &proto.AgentStart{
+ _, err := e.Exec(ctx, "uppercase-task", &proto.AgentStart{
AgentId: "uppercase",
Messages: inputs,
}, handler)
+ return err
}
// Final step: Sandbox -> Done
diff --git a/internal/testagent/agent.go b/internal/testagent/agent.go
index 0a7bf4d..6080249 100644
--- a/internal/testagent/agent.go
+++ b/internal/testagent/agent.go
@@ -99,7 +99,7 @@ func (a *CodingAgent) Connect(ctx context.Context, execID string, start *proto.A
history = append(history, outputs...)
// User may need to take control back to confirm
// or after decline.
- if historyutil.WaitsForUser(history) {
+ if historyutil.WaitsForUser(history) != nil {
return nil
}
}
@@ -121,7 +121,7 @@ func (a *CodingAgent) Connect(ctx context.Context, execID string, start *proto.A
}
history = append(history, outputs...)
- if historyutil.WaitsForUser(history) {
+ if historyutil.WaitsForUser(history) != nil {
return nil
}
}
@@ -330,7 +330,7 @@ func (e *Executor) Exec(ctx context.Context, execID string, start *proto.AgentSt
return nil, err
}
}
- if err := e.exec.Exec(ctx, execID, start, func(resp *proto.AgentOutputs) error {
+ if _, err := e.exec.Exec(ctx, execID, start, func(resp *proto.AgentOutputs) error {
outputs = append(outputs, resp.Messages...)
return e.handler(resp)
}); err != nil {
diff --git a/internal/testagent/proto/testagent.pb.go b/internal/testagent/proto/testagent.pb.go
index da25415..78ae1ea 100644
--- a/internal/testagent/proto/testagent.pb.go
+++ b/internal/testagent/proto/testagent.pb.go
@@ -15,7 +15,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
-// protoc v3.21.12
+// protoc v5.28.2
// source: internal/testagent/proto/testagent.proto
package proto
diff --git a/proto/ax.pb.go b/proto/ax.pb.go
index 25cdf13..bdc57a9 100644
--- a/proto/ax.pb.go
+++ b/proto/ax.pb.go
@@ -15,7 +15,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.11
-// protoc v3.21.12
+// protoc v5.28.2
// source: proto/ax.proto
package proto
@@ -154,8 +154,7 @@ func (x *AgentStart) GetMessages() []*Message {
type AgentOutputs struct {
state protoimpl.MessageState `protogen:"open.v1"`
- Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"`
- CheckpointId string `protobuf:"bytes,2,opt,name=checkpoint_id,json=checkpointId,proto3" json:"checkpoint_id,omitempty"` // TODO: Add awaiting_more field.
+ Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` // TODO: Add awaiting_more field.
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -197,13 +196,6 @@ func (x *AgentOutputs) GetMessages() []*Message {
return nil
}
-func (x *AgentOutputs) GetCheckpointId() string {
- if x != nil {
- return x.CheckpointId
- }
- return ""
-}
-
type AgentMessage struct {
state protoimpl.MessageState `protogen:"open.v1"`
ExecId string `protobuf:"bytes,1,opt,name=exec_id,json=execId,proto3" json:"exec_id,omitempty"`
@@ -821,6 +813,85 @@ func (x *Message) GetContent() *Content {
return nil
}
+// A conversation is the historical session that consist of
+// a number of execution. A conversation cannot be continued
+// before the last execution is completed or failed.
+type ConversationEvent struct {
+ state protoimpl.MessageState `protogen:"open.v1"`
+ ConversationId string `protobuf:"bytes,1,opt,name=conversation_id,json=conversationId,proto3" json:"conversation_id,omitempty"`
+ Seq int32 `protobuf:"varint,2,opt,name=seq,proto3" json:"seq,omitempty"`
+ ExecId string `protobuf:"bytes,3,opt,name=exec_id,json=execId,proto3" json:"exec_id,omitempty"`
+ Messages []*Message `protobuf:"bytes,4,rep,name=messages,proto3" json:"messages,omitempty"`
+ State State `protobuf:"varint,5,opt,name=state,proto3,enum=proto.State" json:"state,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
+}
+
+func (x *ConversationEvent) Reset() {
+ *x = ConversationEvent{}
+ mi := &file_proto_ax_proto_msgTypes[11]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+}
+
+func (x *ConversationEvent) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ConversationEvent) ProtoMessage() {}
+
+func (x *ConversationEvent) ProtoReflect() protoreflect.Message {
+ mi := &file_proto_ax_proto_msgTypes[11]
+ if x != nil {
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ if ms.LoadMessageInfo() == nil {
+ ms.StoreMessageInfo(mi)
+ }
+ return ms
+ }
+ return mi.MessageOf(x)
+}
+
+// Deprecated: Use ConversationEvent.ProtoReflect.Descriptor instead.
+func (*ConversationEvent) Descriptor() ([]byte, []int) {
+ return file_proto_ax_proto_rawDescGZIP(), []int{11}
+}
+
+func (x *ConversationEvent) GetConversationId() string {
+ if x != nil {
+ return x.ConversationId
+ }
+ return ""
+}
+
+func (x *ConversationEvent) GetSeq() int32 {
+ if x != nil {
+ return x.Seq
+ }
+ return 0
+}
+
+func (x *ConversationEvent) GetExecId() string {
+ if x != nil {
+ return x.ExecId
+ }
+ return ""
+}
+
+func (x *ConversationEvent) GetMessages() []*Message {
+ if x != nil {
+ return x.Messages
+ }
+ return nil
+}
+
+func (x *ConversationEvent) GetState() State {
+ if x != nil {
+ return x.State
+ }
+ return State_STATE_UNSPECIFIED
+}
+
// ExecutionEvent is the entry in the event log. ExecutionEvents are used
// to record the actions taken place in the executor.
// The executor can replay the events for resumability.
@@ -828,18 +899,18 @@ type ExecutionEvent struct {
state protoimpl.MessageState `protogen:"open.v1"`
ExecId string `protobuf:"bytes,1,opt,name=exec_id,json=execId,proto3" json:"exec_id,omitempty"`
AgentId string `protobuf:"bytes,2,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"`
- Inputs []*Message `protobuf:"bytes,3,rep,name=inputs,proto3" json:"inputs,omitempty"`
- Outputs []*Message `protobuf:"bytes,4,rep,name=outputs,proto3" json:"outputs,omitempty"`
- State State `protobuf:"varint,5,opt,name=state,proto3,enum=proto.State" json:"state,omitempty"`
- Timestamp *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
- CheckpointId string `protobuf:"bytes,7,opt,name=checkpoint_id,json=checkpointId,proto3" json:"checkpoint_id,omitempty"`
+ AgentConfig *anypb.Any `protobuf:"bytes,3,opt,name=agent_config,json=agentConfig,proto3" json:"agent_config,omitempty"`
+ Inputs []*Message `protobuf:"bytes,4,rep,name=inputs,proto3" json:"inputs,omitempty"`
+ Outputs []*Message `protobuf:"bytes,5,rep,name=outputs,proto3" json:"outputs,omitempty"`
+ State State `protobuf:"varint,6,opt,name=state,proto3,enum=proto.State" json:"state,omitempty"`
+ Timestamp *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ExecutionEvent) Reset() {
*x = ExecutionEvent{}
- mi := &file_proto_ax_proto_msgTypes[11]
+ mi := &file_proto_ax_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -851,7 +922,7 @@ func (x *ExecutionEvent) String() string {
func (*ExecutionEvent) ProtoMessage() {}
func (x *ExecutionEvent) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[11]
+ mi := &file_proto_ax_proto_msgTypes[12]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -864,7 +935,7 @@ func (x *ExecutionEvent) ProtoReflect() protoreflect.Message {
// Deprecated: Use ExecutionEvent.ProtoReflect.Descriptor instead.
func (*ExecutionEvent) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{11}
+ return file_proto_ax_proto_rawDescGZIP(), []int{12}
}
func (x *ExecutionEvent) GetExecId() string {
@@ -881,6 +952,13 @@ func (x *ExecutionEvent) GetAgentId() string {
return ""
}
+func (x *ExecutionEvent) GetAgentConfig() *anypb.Any {
+ if x != nil {
+ return x.AgentConfig
+ }
+ return nil
+}
+
func (x *ExecutionEvent) GetInputs() []*Message {
if x != nil {
return x.Inputs
@@ -909,13 +987,6 @@ func (x *ExecutionEvent) GetTimestamp() *timestamppb.Timestamp {
return nil
}
-func (x *ExecutionEvent) GetCheckpointId() string {
- if x != nil {
- return x.CheckpointId
- }
- return ""
-}
-
// HealthCheckRequest for agent health checks
type HealthCheckRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -925,7 +996,7 @@ type HealthCheckRequest struct {
func (x *HealthCheckRequest) Reset() {
*x = HealthCheckRequest{}
- mi := &file_proto_ax_proto_msgTypes[12]
+ mi := &file_proto_ax_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -937,7 +1008,7 @@ func (x *HealthCheckRequest) String() string {
func (*HealthCheckRequest) ProtoMessage() {}
func (x *HealthCheckRequest) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[12]
+ mi := &file_proto_ax_proto_msgTypes[13]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -950,7 +1021,7 @@ func (x *HealthCheckRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use HealthCheckRequest.ProtoReflect.Descriptor instead.
func (*HealthCheckRequest) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{12}
+ return file_proto_ax_proto_rawDescGZIP(), []int{13}
}
// HealthCheckResponse contains agent health status
@@ -964,7 +1035,7 @@ type HealthCheckResponse struct {
func (x *HealthCheckResponse) Reset() {
*x = HealthCheckResponse{}
- mi := &file_proto_ax_proto_msgTypes[13]
+ mi := &file_proto_ax_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -976,7 +1047,7 @@ func (x *HealthCheckResponse) String() string {
func (*HealthCheckResponse) ProtoMessage() {}
func (x *HealthCheckResponse) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[13]
+ mi := &file_proto_ax_proto_msgTypes[14]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -989,7 +1060,7 @@ func (x *HealthCheckResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use HealthCheckResponse.ProtoReflect.Descriptor instead.
func (*HealthCheckResponse) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{13}
+ return file_proto_ax_proto_rawDescGZIP(), []int{14}
}
func (x *HealthCheckResponse) GetHealthy() bool {
@@ -1008,18 +1079,19 @@ func (x *HealthCheckResponse) GetMessage() string {
// ExecRequest for executing.
type ExecRequest struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // Unique execution identifier
- AgentId string `protobuf:"bytes,2,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"` // Agent ID, if empty planner is used
- AgentConfig *anypb.Any `protobuf:"bytes,3,opt,name=agent_config,json=agentConfig,proto3" json:"agent_config,omitempty"` // Agent configuration if any
- Inputs []*Message `protobuf:"bytes,4,rep,name=inputs,proto3" json:"inputs,omitempty"` // Input content to process
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ state protoimpl.MessageState `protogen:"open.v1"`
+ ConversationId string `protobuf:"bytes,1,opt,name=conversation_id,json=conversationId,proto3" json:"conversation_id,omitempty"` // Unique conversation identifier
+ Inputs []*Message `protobuf:"bytes,2,rep,name=inputs,proto3" json:"inputs,omitempty"` // New inputs
+ LastSeenSeq int32 `protobuf:"varint,3,opt,name=last_seen_seq,json=lastSeenSeq,proto3" json:"last_seen_seq,omitempty"` // Last sequence number seen by the client
+ AgentId string `protobuf:"bytes,4,opt,name=agent_id,json=agentId,proto3" json:"agent_id,omitempty"` // Agent ID, if empty planner is used
+ AgentConfig *anypb.Any `protobuf:"bytes,5,opt,name=agent_config,json=agentConfig,proto3" json:"agent_config,omitempty"` // Agent configuration if any
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *ExecRequest) Reset() {
*x = ExecRequest{}
- mi := &file_proto_ax_proto_msgTypes[14]
+ mi := &file_proto_ax_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1031,7 +1103,7 @@ func (x *ExecRequest) String() string {
func (*ExecRequest) ProtoMessage() {}
func (x *ExecRequest) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[14]
+ mi := &file_proto_ax_proto_msgTypes[15]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1044,16 +1116,30 @@ func (x *ExecRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ExecRequest.ProtoReflect.Descriptor instead.
func (*ExecRequest) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{14}
+ return file_proto_ax_proto_rawDescGZIP(), []int{15}
}
-func (x *ExecRequest) GetId() string {
+func (x *ExecRequest) GetConversationId() string {
if x != nil {
- return x.Id
+ return x.ConversationId
}
return ""
}
+func (x *ExecRequest) GetInputs() []*Message {
+ if x != nil {
+ return x.Inputs
+ }
+ return nil
+}
+
+func (x *ExecRequest) GetLastSeenSeq() int32 {
+ if x != nil {
+ return x.LastSeenSeq
+ }
+ return 0
+}
+
func (x *ExecRequest) GetAgentId() string {
if x != nil {
return x.AgentId
@@ -1068,13 +1154,6 @@ func (x *ExecRequest) GetAgentConfig() *anypb.Any {
return nil
}
-func (x *ExecRequest) GetInputs() []*Message {
- if x != nil {
- return x.Inputs
- }
- return nil
-}
-
// ExecResponse contains the result of an execution.
type ExecResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
@@ -1085,7 +1164,7 @@ type ExecResponse struct {
func (x *ExecResponse) Reset() {
*x = ExecResponse{}
- mi := &file_proto_ax_proto_msgTypes[15]
+ mi := &file_proto_ax_proto_msgTypes[16]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1097,7 +1176,7 @@ func (x *ExecResponse) String() string {
func (*ExecResponse) ProtoMessage() {}
func (x *ExecResponse) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[15]
+ mi := &file_proto_ax_proto_msgTypes[16]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1110,7 +1189,7 @@ func (x *ExecResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ExecResponse.ProtoReflect.Descriptor instead.
func (*ExecResponse) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{15}
+ return file_proto_ax_proto_rawDescGZIP(), []int{16}
}
func (x *ExecResponse) GetOutputs() []*Message {
@@ -1121,17 +1200,14 @@ func (x *ExecResponse) GetOutputs() []*Message {
}
type ForkRequest struct {
- state protoimpl.MessageState `protogen:"open.v1"`
- SrcId string `protobuf:"bytes,1,opt,name=src_id,json=srcId,proto3" json:"src_id,omitempty"`
- SrcCheckpointId string `protobuf:"bytes,2,opt,name=src_checkpoint_id,json=srcCheckpointId,proto3" json:"src_checkpoint_id,omitempty"` // Checkpoint ID within the source execution to fork from.
- DestId string `protobuf:"bytes,3,opt,name=dest_id,json=destId,proto3" json:"dest_id,omitempty"` // New ID. If provided, must not exist.
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ state protoimpl.MessageState `protogen:"open.v1"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *ForkRequest) Reset() {
*x = ForkRequest{}
- mi := &file_proto_ax_proto_msgTypes[16]
+ mi := &file_proto_ax_proto_msgTypes[17]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1143,7 +1219,7 @@ func (x *ForkRequest) String() string {
func (*ForkRequest) ProtoMessage() {}
func (x *ForkRequest) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[16]
+ mi := &file_proto_ax_proto_msgTypes[17]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1156,40 +1232,18 @@ func (x *ForkRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ForkRequest.ProtoReflect.Descriptor instead.
func (*ForkRequest) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{16}
-}
-
-func (x *ForkRequest) GetSrcId() string {
- if x != nil {
- return x.SrcId
- }
- return ""
-}
-
-func (x *ForkRequest) GetSrcCheckpointId() string {
- if x != nil {
- return x.SrcCheckpointId
- }
- return ""
-}
-
-func (x *ForkRequest) GetDestId() string {
- if x != nil {
- return x.DestId
- }
- return ""
+ return file_proto_ax_proto_rawDescGZIP(), []int{17}
}
type ForkResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
- NewId string `protobuf:"bytes,1,opt,name=new_id,json=newId,proto3" json:"new_id,omitempty"` // New task ID (in case it was generated or modified by server)
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *ForkResponse) Reset() {
*x = ForkResponse{}
- mi := &file_proto_ax_proto_msgTypes[17]
+ mi := &file_proto_ax_proto_msgTypes[18]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1201,7 +1255,7 @@ func (x *ForkResponse) String() string {
func (*ForkResponse) ProtoMessage() {}
func (x *ForkResponse) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[17]
+ mi := &file_proto_ax_proto_msgTypes[18]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1214,14 +1268,7 @@ func (x *ForkResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ForkResponse.ProtoReflect.Descriptor instead.
func (*ForkResponse) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{17}
-}
-
-func (x *ForkResponse) GetNewId() string {
- if x != nil {
- return x.NewId
- }
- return ""
+ return file_proto_ax_proto_rawDescGZIP(), []int{18}
}
type RemoteAgentConfig struct {
@@ -1233,7 +1280,7 @@ type RemoteAgentConfig struct {
func (x *RemoteAgentConfig) Reset() {
*x = RemoteAgentConfig{}
- mi := &file_proto_ax_proto_msgTypes[18]
+ mi := &file_proto_ax_proto_msgTypes[19]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1245,7 +1292,7 @@ func (x *RemoteAgentConfig) String() string {
func (*RemoteAgentConfig) ProtoMessage() {}
func (x *RemoteAgentConfig) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[18]
+ mi := &file_proto_ax_proto_msgTypes[19]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1258,7 +1305,7 @@ func (x *RemoteAgentConfig) ProtoReflect() protoreflect.Message {
// Deprecated: Use RemoteAgentConfig.ProtoReflect.Descriptor instead.
func (*RemoteAgentConfig) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{18}
+ return file_proto_ax_proto_rawDescGZIP(), []int{19}
}
func (x *RemoteAgentConfig) GetAddress() string {
@@ -1285,7 +1332,7 @@ type RegisterAgentRequest struct {
func (x *RegisterAgentRequest) Reset() {
*x = RegisterAgentRequest{}
- mi := &file_proto_ax_proto_msgTypes[19]
+ mi := &file_proto_ax_proto_msgTypes[20]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1297,7 +1344,7 @@ func (x *RegisterAgentRequest) String() string {
func (*RegisterAgentRequest) ProtoMessage() {}
func (x *RegisterAgentRequest) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[19]
+ mi := &file_proto_ax_proto_msgTypes[20]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1310,7 +1357,7 @@ func (x *RegisterAgentRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use RegisterAgentRequest.ProtoReflect.Descriptor instead.
func (*RegisterAgentRequest) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{19}
+ return file_proto_ax_proto_rawDescGZIP(), []int{20}
}
func (x *RegisterAgentRequest) GetAgentId() string {
@@ -1377,7 +1424,7 @@ type RegisterAgentResponse struct {
func (x *RegisterAgentResponse) Reset() {
*x = RegisterAgentResponse{}
- mi := &file_proto_ax_proto_msgTypes[20]
+ mi := &file_proto_ax_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1389,7 +1436,7 @@ func (x *RegisterAgentResponse) String() string {
func (*RegisterAgentResponse) ProtoMessage() {}
func (x *RegisterAgentResponse) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[20]
+ mi := &file_proto_ax_proto_msgTypes[21]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1402,7 +1449,7 @@ func (x *RegisterAgentResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use RegisterAgentResponse.ProtoReflect.Descriptor instead.
func (*RegisterAgentResponse) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{20}
+ return file_proto_ax_proto_rawDescGZIP(), []int{21}
}
func (x *RegisterAgentResponse) GetHealthy() bool {
@@ -1425,7 +1472,7 @@ type GeminiConfig struct {
func (x *GeminiConfig) Reset() {
*x = GeminiConfig{}
- mi := &file_proto_ax_proto_msgTypes[21]
+ mi := &file_proto_ax_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -1437,7 +1484,7 @@ func (x *GeminiConfig) String() string {
func (*GeminiConfig) ProtoMessage() {}
func (x *GeminiConfig) ProtoReflect() protoreflect.Message {
- mi := &file_proto_ax_proto_msgTypes[21]
+ mi := &file_proto_ax_proto_msgTypes[22]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -1450,7 +1497,7 @@ func (x *GeminiConfig) ProtoReflect() protoreflect.Message {
// Deprecated: Use GeminiConfig.ProtoReflect.Descriptor instead.
func (*GeminiConfig) Descriptor() ([]byte, []int) {
- return file_proto_ax_proto_rawDescGZIP(), []int{21}
+ return file_proto_ax_proto_rawDescGZIP(), []int{22}
}
func (x *GeminiConfig) GetModel() string {
@@ -1490,10 +1537,9 @@ const file_proto_ax_proto_rawDesc = "" +
"AgentStart\x12\x19\n" +
"\bagent_id\x18\x01 \x01(\tR\aagentId\x12,\n" +
"\x06config\x18\x02 \x01(\v2\x14.google.protobuf.AnyR\x06config\x12*\n" +
- "\bmessages\x18\x03 \x03(\v2\x0e.proto.MessageR\bmessages\"_\n" +
+ "\bmessages\x18\x03 \x03(\v2\x0e.proto.MessageR\bmessages\":\n" +
"\fAgentOutputs\x12*\n" +
- "\bmessages\x18\x01 \x03(\v2\x0e.proto.MessageR\bmessages\x12#\n" +
- "\rcheckpoint_id\x18\x02 \x01(\tR\fcheckpointId\"\x8a\x01\n" +
+ "\bmessages\x18\x01 \x03(\v2\x0e.proto.MessageR\bmessages\"\x8a\x01\n" +
"\fAgentMessage\x12\x17\n" +
"\aexec_id\x18\x01 \x01(\tR\x06execId\x12)\n" +
"\x05start\x18\x02 \x01(\v2\x11.proto.AgentStartH\x00R\x05start\x12/\n" +
@@ -1531,32 +1577,35 @@ const file_proto_ax_proto_rawDesc = "" +
"J\x04\b\v\x10\x1a\"G\n" +
"\aMessage\x12\x12\n" +
"\x04role\x18\x01 \x01(\tR\x04role\x12(\n" +
- "\acontent\x18\x02 \x01(\v2\x0e.proto.ContentR\acontent\"\x99\x02\n" +
+ "\acontent\x18\x02 \x01(\v2\x0e.proto.ContentR\acontent\"\xb7\x01\n" +
+ "\x11ConversationEvent\x12'\n" +
+ "\x0fconversation_id\x18\x01 \x01(\tR\x0econversationId\x12\x10\n" +
+ "\x03seq\x18\x02 \x01(\x05R\x03seq\x12\x17\n" +
+ "\aexec_id\x18\x03 \x01(\tR\x06execId\x12*\n" +
+ "\bmessages\x18\x04 \x03(\v2\x0e.proto.MessageR\bmessages\x12\"\n" +
+ "\x05state\x18\x05 \x01(\x0e2\f.proto.StateR\x05state\"\xad\x02\n" +
"\x0eExecutionEvent\x12\x17\n" +
"\aexec_id\x18\x01 \x01(\tR\x06execId\x12\x19\n" +
- "\bagent_id\x18\x02 \x01(\tR\aagentId\x12&\n" +
- "\x06inputs\x18\x03 \x03(\v2\x0e.proto.MessageR\x06inputs\x12(\n" +
- "\aoutputs\x18\x04 \x03(\v2\x0e.proto.MessageR\aoutputs\x12\"\n" +
- "\x05state\x18\x05 \x01(\x0e2\f.proto.StateR\x05state\x128\n" +
- "\ttimestamp\x18\x06 \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\x12#\n" +
- "\rcheckpoint_id\x18\a \x01(\tR\fcheckpointId\"\x14\n" +
+ "\bagent_id\x18\x02 \x01(\tR\aagentId\x127\n" +
+ "\fagent_config\x18\x03 \x01(\v2\x14.google.protobuf.AnyR\vagentConfig\x12&\n" +
+ "\x06inputs\x18\x04 \x03(\v2\x0e.proto.MessageR\x06inputs\x12(\n" +
+ "\aoutputs\x18\x05 \x03(\v2\x0e.proto.MessageR\aoutputs\x12\"\n" +
+ "\x05state\x18\x06 \x01(\x0e2\f.proto.StateR\x05state\x128\n" +
+ "\ttimestamp\x18\a \x01(\v2\x1a.google.protobuf.TimestampR\ttimestamp\"\x14\n" +
"\x12HealthCheckRequest\"I\n" +
"\x13HealthCheckResponse\x12\x18\n" +
"\ahealthy\x18\x01 \x01(\bR\ahealthy\x12\x18\n" +
- "\amessage\x18\x02 \x01(\tR\amessage\"\x99\x01\n" +
- "\vExecRequest\x12\x0e\n" +
- "\x02id\x18\x01 \x01(\tR\x02id\x12\x19\n" +
- "\bagent_id\x18\x02 \x01(\tR\aagentId\x127\n" +
- "\fagent_config\x18\x03 \x01(\v2\x14.google.protobuf.AnyR\vagentConfig\x12&\n" +
- "\x06inputs\x18\x04 \x03(\v2\x0e.proto.MessageR\x06inputs\"8\n" +
+ "\amessage\x18\x02 \x01(\tR\amessage\"\xd6\x01\n" +
+ "\vExecRequest\x12'\n" +
+ "\x0fconversation_id\x18\x01 \x01(\tR\x0econversationId\x12&\n" +
+ "\x06inputs\x18\x02 \x03(\v2\x0e.proto.MessageR\x06inputs\x12\"\n" +
+ "\rlast_seen_seq\x18\x03 \x01(\x05R\vlastSeenSeq\x12\x19\n" +
+ "\bagent_id\x18\x04 \x01(\tR\aagentId\x127\n" +
+ "\fagent_config\x18\x05 \x01(\v2\x14.google.protobuf.AnyR\vagentConfig\"8\n" +
"\fExecResponse\x12(\n" +
- "\aoutputs\x18\x01 \x03(\v2\x0e.proto.MessageR\aoutputs\"i\n" +
- "\vForkRequest\x12\x15\n" +
- "\x06src_id\x18\x01 \x01(\tR\x05srcId\x12*\n" +
- "\x11src_checkpoint_id\x18\x02 \x01(\tR\x0fsrcCheckpointId\x12\x17\n" +
- "\adest_id\x18\x03 \x01(\tR\x06destId\"%\n" +
- "\fForkResponse\x12\x15\n" +
- "\x06new_id\x18\x01 \x01(\tR\x05newId\"-\n" +
+ "\aoutputs\x18\x01 \x03(\v2\x0e.proto.MessageR\aoutputs\"\r\n" +
+ "\vForkRequest\"\x0e\n" +
+ "\fForkResponse\"-\n" +
"\x11RemoteAgentConfig\x12\x18\n" +
"\aaddress\x18\x01 \x01(\tR\aaddress\"\xa9\x02\n" +
"\x14RegisterAgentRequest\x12\x19\n" +
@@ -1603,7 +1652,7 @@ func file_proto_ax_proto_rawDescGZIP() []byte {
}
var file_proto_ax_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
-var file_proto_ax_proto_msgTypes = make([]protoimpl.MessageInfo, 23)
+var file_proto_ax_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_proto_ax_proto_goTypes = []any{
(State)(0), // 0: proto.State
(*AgentStart)(nil), // 1: proto.AgentStart
@@ -1617,63 +1666,67 @@ var file_proto_ax_proto_goTypes = []any{
(*FunctionResponseContent)(nil), // 9: proto.FunctionResponseContent
(*Content)(nil), // 10: proto.Content
(*Message)(nil), // 11: proto.Message
- (*ExecutionEvent)(nil), // 12: proto.ExecutionEvent
- (*HealthCheckRequest)(nil), // 13: proto.HealthCheckRequest
- (*HealthCheckResponse)(nil), // 14: proto.HealthCheckResponse
- (*ExecRequest)(nil), // 15: proto.ExecRequest
- (*ExecResponse)(nil), // 16: proto.ExecResponse
- (*ForkRequest)(nil), // 17: proto.ForkRequest
- (*ForkResponse)(nil), // 18: proto.ForkResponse
- (*RemoteAgentConfig)(nil), // 19: proto.RemoteAgentConfig
- (*RegisterAgentRequest)(nil), // 20: proto.RegisterAgentRequest
- (*RegisterAgentResponse)(nil), // 21: proto.RegisterAgentResponse
- (*GeminiConfig)(nil), // 22: proto.GeminiConfig
- nil, // 23: proto.RegisterAgentRequest.MetadataEntry
- (*anypb.Any)(nil), // 24: google.protobuf.Any
- (*structpb.Struct)(nil), // 25: google.protobuf.Struct
- (*timestamppb.Timestamp)(nil), // 26: google.protobuf.Timestamp
- (*durationpb.Duration)(nil), // 27: google.protobuf.Duration
+ (*ConversationEvent)(nil), // 12: proto.ConversationEvent
+ (*ExecutionEvent)(nil), // 13: proto.ExecutionEvent
+ (*HealthCheckRequest)(nil), // 14: proto.HealthCheckRequest
+ (*HealthCheckResponse)(nil), // 15: proto.HealthCheckResponse
+ (*ExecRequest)(nil), // 16: proto.ExecRequest
+ (*ExecResponse)(nil), // 17: proto.ExecResponse
+ (*ForkRequest)(nil), // 18: proto.ForkRequest
+ (*ForkResponse)(nil), // 19: proto.ForkResponse
+ (*RemoteAgentConfig)(nil), // 20: proto.RemoteAgentConfig
+ (*RegisterAgentRequest)(nil), // 21: proto.RegisterAgentRequest
+ (*RegisterAgentResponse)(nil), // 22: proto.RegisterAgentResponse
+ (*GeminiConfig)(nil), // 23: proto.GeminiConfig
+ nil, // 24: proto.RegisterAgentRequest.MetadataEntry
+ (*anypb.Any)(nil), // 25: google.protobuf.Any
+ (*structpb.Struct)(nil), // 26: google.protobuf.Struct
+ (*timestamppb.Timestamp)(nil), // 27: google.protobuf.Timestamp
+ (*durationpb.Duration)(nil), // 28: google.protobuf.Duration
}
var file_proto_ax_proto_depIdxs = []int32{
- 24, // 0: proto.AgentStart.config:type_name -> google.protobuf.Any
+ 25, // 0: proto.AgentStart.config:type_name -> google.protobuf.Any
11, // 1: proto.AgentStart.messages:type_name -> proto.Message
11, // 2: proto.AgentOutputs.messages:type_name -> proto.Message
1, // 3: proto.AgentMessage.start:type_name -> proto.AgentStart
2, // 4: proto.AgentMessage.outputs:type_name -> proto.AgentOutputs
5, // 5: proto.ConfirmationContent.approval:type_name -> proto.ApprovalDecision
6, // 6: proto.ConfirmationContent.decline:type_name -> proto.DeclineDecision
- 25, // 7: proto.FunctionCallContent.args:type_name -> google.protobuf.Struct
- 25, // 8: proto.FunctionResponseContent.response:type_name -> google.protobuf.Struct
+ 26, // 7: proto.FunctionCallContent.args:type_name -> google.protobuf.Struct
+ 26, // 8: proto.FunctionResponseContent.response:type_name -> google.protobuf.Struct
4, // 9: proto.Content.text:type_name -> proto.TextContent
7, // 10: proto.Content.confirmation:type_name -> proto.ConfirmationContent
8, // 11: proto.Content.function_call:type_name -> proto.FunctionCallContent
9, // 12: proto.Content.function_response:type_name -> proto.FunctionResponseContent
10, // 13: proto.Message.content:type_name -> proto.Content
- 11, // 14: proto.ExecutionEvent.inputs:type_name -> proto.Message
- 11, // 15: proto.ExecutionEvent.outputs:type_name -> proto.Message
- 0, // 16: proto.ExecutionEvent.state:type_name -> proto.State
- 26, // 17: proto.ExecutionEvent.timestamp:type_name -> google.protobuf.Timestamp
- 24, // 18: proto.ExecRequest.agent_config:type_name -> google.protobuf.Any
- 11, // 19: proto.ExecRequest.inputs:type_name -> proto.Message
- 11, // 20: proto.ExecResponse.outputs:type_name -> proto.Message
- 23, // 21: proto.RegisterAgentRequest.metadata:type_name -> proto.RegisterAgentRequest.MetadataEntry
- 19, // 22: proto.RegisterAgentRequest.remote:type_name -> proto.RemoteAgentConfig
- 27, // 23: proto.GeminiConfig.timeout:type_name -> google.protobuf.Duration
- 3, // 24: proto.AgentService.Connect:input_type -> proto.AgentMessage
- 13, // 25: proto.AgentService.HealthCheck:input_type -> proto.HealthCheckRequest
- 15, // 26: proto.AXService.Exec:input_type -> proto.ExecRequest
- 17, // 27: proto.AXService.Fork:input_type -> proto.ForkRequest
- 20, // 28: proto.AXService.RegisterAgent:input_type -> proto.RegisterAgentRequest
- 3, // 29: proto.AgentService.Connect:output_type -> proto.AgentMessage
- 14, // 30: proto.AgentService.HealthCheck:output_type -> proto.HealthCheckResponse
- 16, // 31: proto.AXService.Exec:output_type -> proto.ExecResponse
- 18, // 32: proto.AXService.Fork:output_type -> proto.ForkResponse
- 21, // 33: proto.AXService.RegisterAgent:output_type -> proto.RegisterAgentResponse
- 29, // [29:34] is the sub-list for method output_type
- 24, // [24:29] is the sub-list for method input_type
- 24, // [24:24] is the sub-list for extension type_name
- 24, // [24:24] is the sub-list for extension extendee
- 0, // [0:24] is the sub-list for field type_name
+ 11, // 14: proto.ConversationEvent.messages:type_name -> proto.Message
+ 0, // 15: proto.ConversationEvent.state:type_name -> proto.State
+ 25, // 16: proto.ExecutionEvent.agent_config:type_name -> google.protobuf.Any
+ 11, // 17: proto.ExecutionEvent.inputs:type_name -> proto.Message
+ 11, // 18: proto.ExecutionEvent.outputs:type_name -> proto.Message
+ 0, // 19: proto.ExecutionEvent.state:type_name -> proto.State
+ 27, // 20: proto.ExecutionEvent.timestamp:type_name -> google.protobuf.Timestamp
+ 11, // 21: proto.ExecRequest.inputs:type_name -> proto.Message
+ 25, // 22: proto.ExecRequest.agent_config:type_name -> google.protobuf.Any
+ 11, // 23: proto.ExecResponse.outputs:type_name -> proto.Message
+ 24, // 24: proto.RegisterAgentRequest.metadata:type_name -> proto.RegisterAgentRequest.MetadataEntry
+ 20, // 25: proto.RegisterAgentRequest.remote:type_name -> proto.RemoteAgentConfig
+ 28, // 26: proto.GeminiConfig.timeout:type_name -> google.protobuf.Duration
+ 3, // 27: proto.AgentService.Connect:input_type -> proto.AgentMessage
+ 14, // 28: proto.AgentService.HealthCheck:input_type -> proto.HealthCheckRequest
+ 16, // 29: proto.AXService.Exec:input_type -> proto.ExecRequest
+ 18, // 30: proto.AXService.Fork:input_type -> proto.ForkRequest
+ 21, // 31: proto.AXService.RegisterAgent:input_type -> proto.RegisterAgentRequest
+ 3, // 32: proto.AgentService.Connect:output_type -> proto.AgentMessage
+ 15, // 33: proto.AgentService.HealthCheck:output_type -> proto.HealthCheckResponse
+ 17, // 34: proto.AXService.Exec:output_type -> proto.ExecResponse
+ 19, // 35: proto.AXService.Fork:output_type -> proto.ForkResponse
+ 22, // 36: proto.AXService.RegisterAgent:output_type -> proto.RegisterAgentResponse
+ 32, // [32:37] is the sub-list for method output_type
+ 27, // [27:32] is the sub-list for method input_type
+ 27, // [27:27] is the sub-list for extension type_name
+ 27, // [27:27] is the sub-list for extension extendee
+ 0, // [0:27] is the sub-list for field type_name
}
func init() { file_proto_ax_proto_init() }
@@ -1695,7 +1748,7 @@ func file_proto_ax_proto_init() {
(*Content_FunctionCall)(nil),
(*Content_FunctionResponse)(nil),
}
- file_proto_ax_proto_msgTypes[19].OneofWrappers = []any{
+ file_proto_ax_proto_msgTypes[20].OneofWrappers = []any{
(*RegisterAgentRequest_Remote)(nil),
}
type x struct{}
@@ -1704,7 +1757,7 @@ func file_proto_ax_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_ax_proto_rawDesc), len(file_proto_ax_proto_rawDesc)),
NumEnums: 1,
- NumMessages: 23,
+ NumMessages: 24,
NumExtensions: 0,
NumServices: 2,
},
diff --git a/proto/ax.proto b/proto/ax.proto
index c016672..952a19a 100644
--- a/proto/ax.proto
+++ b/proto/ax.proto
@@ -31,7 +31,6 @@ message AgentStart {
message AgentOutputs {
repeated Message messages = 1;
- string checkpoint_id = 2;
// TODO: Add awaiting_more field.
}
@@ -106,17 +105,28 @@ message Message {
Content content = 2; // content of the message
}
+// A conversation is the historical session that consist of
+// a number of execution. A conversation cannot be continued
+// before the last execution is completed or failed.
+message ConversationEvent {
+ string conversation_id = 1;
+ int32 seq = 2;
+ string exec_id = 3;
+ repeated Message messages = 4;
+ State state = 5;
+}
+
// ExecutionEvent is the entry in the event log. ExecutionEvents are used
// to record the actions taken place in the executor.
// The executor can replay the events for resumability.
message ExecutionEvent {
string exec_id = 1;
string agent_id = 2;
- repeated Message inputs = 3;
- repeated Message outputs = 4;
- State state = 5;
- google.protobuf.Timestamp timestamp = 6;
- string checkpoint_id = 7;
+ google.protobuf.Any agent_config = 3;
+ repeated Message inputs = 4;
+ repeated Message outputs = 5;
+ State state = 6;
+ google.protobuf.Timestamp timestamp = 7;
}
// HealthCheckRequest for agent health checks
@@ -147,25 +157,25 @@ enum State {
// ExecRequest for executing.
message ExecRequest {
- string id = 1; // Unique execution identifier
- string agent_id = 2; // Agent ID, if empty planner is used
- google.protobuf.Any agent_config = 3; // Agent configuration if any
- repeated Message inputs = 4; // Input content to process
+ string conversation_id = 1; // Unique conversation identifier
+ repeated Message inputs = 2; // New inputs
+ int32 last_seen_seq = 3; // Last sequence number seen by the client
+
+ string agent_id = 4; // Agent ID, if empty planner is used
+ google.protobuf.Any agent_config = 5; // Agent configuration if any
}
// ExecResponse contains the result of an execution.
message ExecResponse {
repeated Message outputs = 1; // Output content
+ // TODO: int32 seq = 2;
+ // TODO: State state = 3;
}
message ForkRequest {
- string src_id = 1;
- string src_checkpoint_id = 2; // Checkpoint ID within the source execution to fork from.
- string dest_id = 3; // New ID. If provided, must not exist.
}
message ForkResponse {
- string new_id = 1; // New task ID (in case it was generated or modified by server)
}
message RemoteAgentConfig {
@@ -191,10 +201,10 @@ message RegisterAgentResponse {
// AXService defines the gRPC service for AX operations
service AXService {
// Exec executes an agentic task or resumes an existing one with streaming responses
- // If the execution id already exists, it will be resumed from the last checkpoint.
+ // If the conversation_id already exists, it will be resumed.
rpc Exec(ExecRequest) returns (stream ExecResponse);
- // Fork forks an event log from a specific checkpoint.
+ // Fork forks an event log from a specific conversation.
rpc Fork(ForkRequest) returns (ForkResponse);
// RegisterAgent registers a new agent with the controller
diff --git a/proto/ax_grpc.pb.go b/proto/ax_grpc.pb.go
index f99df80..d7c6c0e 100644
--- a/proto/ax_grpc.pb.go
+++ b/proto/ax_grpc.pb.go
@@ -14,8 +14,8 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
-// - protoc-gen-go-grpc v1.6.1
-// - protoc v3.21.12
+// - protoc-gen-go-grpc v1.5.1
+// - protoc v5.28.2
// source: proto/ax.proto
package proto
@@ -101,10 +101,10 @@ type AgentServiceServer interface {
type UnimplementedAgentServiceServer struct{}
func (UnimplementedAgentServiceServer) Connect(grpc.BidiStreamingServer[AgentMessage, AgentMessage]) error {
- return status.Error(codes.Unimplemented, "method Connect not implemented")
+ return status.Errorf(codes.Unimplemented, "method Connect not implemented")
}
func (UnimplementedAgentServiceServer) HealthCheck(context.Context, *HealthCheckRequest) (*HealthCheckResponse, error) {
- return nil, status.Error(codes.Unimplemented, "method HealthCheck not implemented")
+ return nil, status.Errorf(codes.Unimplemented, "method HealthCheck not implemented")
}
func (UnimplementedAgentServiceServer) mustEmbedUnimplementedAgentServiceServer() {}
func (UnimplementedAgentServiceServer) testEmbeddedByValue() {}
@@ -117,7 +117,7 @@ type UnsafeAgentServiceServer interface {
}
func RegisterAgentServiceServer(s grpc.ServiceRegistrar, srv AgentServiceServer) {
- // If the following call panics, it indicates UnimplementedAgentServiceServer was
+ // If the following call pancis, it indicates UnimplementedAgentServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
@@ -188,9 +188,9 @@ const (
// AXService defines the gRPC service for AX operations
type AXServiceClient interface {
// Exec executes an agentic task or resumes an existing one with streaming responses
- // If the execution id already exists, it will be resumed from the last checkpoint.
+ // If the conversation_id already exists, it will be resumed.
Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[ExecResponse], error)
- // Fork forks an event log from a specific checkpoint.
+ // Fork forks an event log from a specific conversation.
Fork(ctx context.Context, in *ForkRequest, opts ...grpc.CallOption) (*ForkResponse, error)
// RegisterAgent registers a new agent with the controller
RegisterAgent(ctx context.Context, in *RegisterAgentRequest, opts ...grpc.CallOption) (*RegisterAgentResponse, error)
@@ -250,9 +250,9 @@ func (c *aXServiceClient) RegisterAgent(ctx context.Context, in *RegisterAgentRe
// AXService defines the gRPC service for AX operations
type AXServiceServer interface {
// Exec executes an agentic task or resumes an existing one with streaming responses
- // If the execution id already exists, it will be resumed from the last checkpoint.
+ // If the conversation_id already exists, it will be resumed.
Exec(*ExecRequest, grpc.ServerStreamingServer[ExecResponse]) error
- // Fork forks an event log from a specific checkpoint.
+ // Fork forks an event log from a specific conversation.
Fork(context.Context, *ForkRequest) (*ForkResponse, error)
// RegisterAgent registers a new agent with the controller
RegisterAgent(context.Context, *RegisterAgentRequest) (*RegisterAgentResponse, error)
@@ -267,13 +267,13 @@ type AXServiceServer interface {
type UnimplementedAXServiceServer struct{}
func (UnimplementedAXServiceServer) Exec(*ExecRequest, grpc.ServerStreamingServer[ExecResponse]) error {
- return status.Error(codes.Unimplemented, "method Exec not implemented")
+ return status.Errorf(codes.Unimplemented, "method Exec not implemented")
}
func (UnimplementedAXServiceServer) Fork(context.Context, *ForkRequest) (*ForkResponse, error) {
- return nil, status.Error(codes.Unimplemented, "method Fork not implemented")
+ return nil, status.Errorf(codes.Unimplemented, "method Fork not implemented")
}
func (UnimplementedAXServiceServer) RegisterAgent(context.Context, *RegisterAgentRequest) (*RegisterAgentResponse, error) {
- return nil, status.Error(codes.Unimplemented, "method RegisterAgent not implemented")
+ return nil, status.Errorf(codes.Unimplemented, "method RegisterAgent not implemented")
}
func (UnimplementedAXServiceServer) mustEmbedUnimplementedAXServiceServer() {}
func (UnimplementedAXServiceServer) testEmbeddedByValue() {}
@@ -286,7 +286,7 @@ type UnsafeAXServiceServer interface {
}
func RegisterAXServiceServer(s grpc.ServiceRegistrar, srv AXServiceServer) {
- // If the following call panics, it indicates UnimplementedAXServiceServer was
+ // If the following call pancis, it indicates UnimplementedAXServiceServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.