Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Allow internal_only events (#191)
Jaana Dogan6ad38cc680ea
diff --git a/internal/controller/controller.go b/internal/controller/controller.goindex 3982858..1cf1157 100644--- a/internal/controller/controller.go+++ b/internal/controller/controller.go@@ -210,6 +210,9 @@ func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler Efunc (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 ExecHandler) error {e := executor.DefaultExecutor(d.eventLog, registry)outputCapturer := func(outgoing *proto.AgentOutputs) error {+ if outgoing.InternalOnly {+ return nil+ }msg := &proto.ConversationEvent{ConversationId: conversationID,ExecId: execID,diff --git a/internal/controller/controller_test.go b/internal/controller/controller_test.goindex ee0691f..9c732d3 100644--- a/internal/controller/controller_test.go+++ b/internal/controller/controller_test.go@@ -356,3 +356,147 @@ func TestController_Exec_WaitsForConfirmation(t *testing.T) {}}+func TestController_Exec_InternalOnly(t *testing.T) {+ ctx := context.Background()+ cid := "test-conv-internal"++ log := &mockEventLog{}++ // Create an agent that emits one internal-only message and one regular message.+ a := &mockAgentFunc{+ connectFunc: func(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {+ // If we already have the public message in history, don't emit anything.+ for _, m := range start.Messages {+ if m.GetContent().GetText().GetText() == "public message" {+ return nil+ }+ }+ // Emit internal-only message+ if err := o(&proto.AgentOutputs{+ Messages: []*proto.Message{+ {Role: "assistant", Content: &proto.Content{Content: &proto.Content_Text{Text: &proto.TextContent{Text: "internal message"}}}},+ },+ InternalOnly: true,+ }); err != nil {+ return err+ }+ // Emit regular message+ return o(&proto.AgentOutputs{+ Messages: []*proto.Message{+ {Role: "assistant", Content: &proto.Content{Content: &proto.Content_Text{Text: &proto.TextContent{Text: "public message"}}}},+ },+ })+ },+ }++ c, err := New(ctx, Config{+ EventLogBuilder: func() (executor.EventLog, error) {+ return log, nil+ },+ PlannerBuilder: func(ctx context.Context, r *Registry) (agent.Agent, error) {+ return a, nil+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ defer c.Close()++ var msgs []*proto.Message+ handler := ExecHandler(func(resp *proto.ExecResponse) error {+ msgs = append(msgs, resp.Outputs...)+ return nil+ })++ err = c.Exec(ctx, &proto.ExecRequest{+ ConversationId: cid,+ Inputs: []*proto.Message{+ {Role: "user", Content: &proto.Content{Content: &proto.Content_Text{Text: &proto.TextContent{Text: "hello"}}}},+ },+ }, handler)+ if err != nil {+ t.Fatal(err)+ }++ // Verify that ONLY the public message was emitted.+ if len(msgs) != 1 {+ t.Fatalf("expected 1 message emitted, got %d", len(msgs))+ }+ if msgs[0].GetContent().GetText().GetText() != "public message" {+ t.Fatalf("expected 'public message', got %v", msgs[0].GetContent().GetText().GetText())+ }++ // Verify that internal messages are NOT stored in ConversationEvent.+ if len(log.events) != 3 {+ t.Fatalf("expected 3 events in log.events, got %d", len(log.events))+ }++ // Event 0: Inputs+ // Event 1: Public message+ if log.events[1].Messages[0].GetContent().GetText().GetText() != "public message" {+ t.Fatalf("expected 'public message' in log.events, got %v", log.events[1].Messages[0].GetContent().GetText().GetText())+ }++ // Verify that BOTH messages ARE stored in ExecutionEvent.+ if len(log.execEvents) != 3 {+ t.Fatalf("expected 3 events in log.execEvents, got %d", len(log.execEvents))+ }++ // Event 1 in execEvents should contain both outputs.+ outputs := log.execEvents[1].Outputs+ if len(outputs) != 2 {+ t.Fatalf("expected 2 outputs in execEvent, got %d", len(outputs))+ }+ if outputs[0].GetContent().GetText().GetText() != "internal message" {+ t.Fatalf("expected 'internal message' in execEvent, got %v", outputs[0].GetContent().GetText().GetText())+ }+ if outputs[1].GetContent().GetText().GetText() != "public message" {+ t.Fatalf("expected 'public message' in execEvent, got %v", outputs[1].GetContent().GetText().GetText())+ }++ // Test resumption with LastSeenSeq+ var resumedMsgs []*proto.Message+ resumedHandler := ExecHandler(func(resp *proto.ExecResponse) error {+ resumedMsgs = append(resumedMsgs, resp.Outputs...)+ return nil+ })++ c2, err := New(ctx, Config{+ EventLogBuilder: func() (executor.EventLog, error) {+ return log, nil+ },+ PlannerBuilder: func(ctx context.Context, r *Registry) (agent.Agent, error) {+ return a, nil+ },+ })+ if err != nil {+ t.Fatal(err)+ }+ defer c2.Close()++ err = c2.Exec(ctx, &proto.ExecRequest{+ ConversationId: cid,+ LastSeenSeq: 1,+ }, resumedHandler)+ if err != nil {+ t.Fatal(err)+ }++ if len(resumedMsgs) != 1 {+ t.Fatalf("expected 1 message resumed, got %d", len(resumedMsgs))+ }+ if resumedMsgs[0].GetContent().GetText().GetText() != "public message" {+ t.Fatalf("expected 'public message' resumed, got %v", resumedMsgs[0].GetContent().GetText().GetText())+ }+}++type mockAgentFunc struct {+ connectFunc func(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error+}++func (m *mockAgentFunc) Connect(ctx context.Context, execID string, start *proto.AgentStart, e agent.Executor, o agent.OutputHandler) error {+ return m.connectFunc(ctx, execID, start, e, o)+}+func (m *mockAgentFunc) HealthCheck(ctx context.Context) error { return nil }+func (m *mockAgentFunc) Close() error { return nil }+diff --git a/proto/ax.pb.go b/proto/ax.pb.goindex 24bcbc2..b3c66e5 100644--- a/proto/ax.pb.go+++ b/proto/ax.pb.go@@ -153,8 +153,12 @@ 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"` // TODO: Add awaiting_more field.+ state protoimpl.MessageState `protogen:"open.v1"`+ Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"`+ // If true, these outputs are stored only in the execution log+ // (for resumption) and are not emitted to the client or stored+ // in the conversation history.+ InternalOnly bool `protobuf:"varint,2,opt,name=internal_only,json=internalOnly,proto3" json:"internal_only,omitempty"`unknownFields protoimpl.UnknownFieldssizeCache protoimpl.SizeCache}@@ -196,6 +200,13 @@ func (x *AgentOutputs) GetMessages() []*Message {return nil}+func (x *AgentOutputs) GetInternalOnly() bool {+ if x != nil {+ return x.InternalOnly+ }+ return false+}+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"`@@ -1545,9 +1556,10 @@ 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\"\x8a\x01\n" ++ "\bmessages\x18\x01 \x03(\v2\x0e.proto.MessageR\bmessages\x12#\n" ++ "\rinternal_only\x18\x02 \x01(\bR\finternalOnly\"\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" +diff --git a/proto/ax.proto b/proto/ax.protoindex 27887cf..0a66e9a 100644--- a/proto/ax.proto+++ b/proto/ax.proto@@ -31,6 +31,12 @@ message AgentStart {message AgentOutputs {repeated Message messages = 1;++ // If true, these outputs are stored only in the execution log+ // (for resumption) and are not emitted to the client or stored+ // in the conversation history.+ bool internal_only = 2;+// TODO: Add awaiting_more field.}