Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Update the Python interface (#101)
Jaana Doganfb83947add60
diff --git a/.gitignore b/.gitignoreindex e68ff05..e2890f2 100644--- a/.gitignore+++ b/.gitignore@@ -10,4 +10,6 @@ google-cloud-sdk/test-sandbox-config.yamlsandbox-routerexamples/sandbox_agent/cloudbuild.yaml-tasklog/*\ No newline at end of file+tasklog/*+python/__pycache__+python/proto/__pycache__\ No newline at end of filediff --git a/README.md b/README.mdindex 48c4cd3..86a3b06 100644--- a/README.md+++ b/README.md@@ -443,15 +443,15 @@ To build a Python agent, first set up your environment by installing dependenciepip install grpcio grpcio-tools# Generate Python code from proto file-python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. proto/ax.proto+python -m grpc_tools.protoc -I. --python_out=python --grpc_python_out=python proto/ax.proto```-See `examples/python_agent/agent.py` for a complete implementation.+See `python/example_agent.py` for a complete implementation.**Register and use:**```bash# Start the Python agent-python agent.py+python python/example_agent.py# Register the agent (in another terminal)ax register \diff --git a/python/ax.py b/python/ax.pyindex 0a2e5f5..e76aee9 100644--- a/python/ax.py+++ b/python/ax.py@@ -28,10 +28,9 @@ class Agent:Agent provides a simple framework for building Python agents.Usage:+ import proto.ax_pb2 as pb2def process(execution_id, inputs):- for content in inputs:- yield Content(role="assistant", type="text",- mimetype="text/plain", data=f"Processed: {content.data}")+ # Implement the agent...agent = Agent(process_func=process)agent.serve(port=50051)@@ -99,7 +98,7 @@ class Agent:except ImportError:raise ImportError("Proto files not found. Generate them first:\n"- " python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. proto/ax.proto"+ " python -m grpc_tools.protoc -I. --python_out=python --grpc_python_out=python proto/ax.proto")server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers))diff --git a/python/example_agent.py b/python/example_agent.pyindex eadf378..0f29b00 100644--- a/python/example_agent.py+++ b/python/example_agent.py@@ -25,13 +25,19 @@ import proto.ax_pb2 as pb2def process(execution_id, inputs):"""Process incoming content list and yield responses"""- for content in inputs:- yield pb2.Content(- role="assistant",- type="text",- mimetype="text/plain",- data=f"Python processed (execution {execution_id}): {content.data.upper()}"- )+ for req in inputs:+ for content in req.contents:+ if content.HasField("text"):+ yield pb2.ProcessResponse(+ contents=[+ pb2.Content(+ role="assistant",+ text=pb2.TextContent(+ text=f"Python processed (execution {execution_id}): {content.text.text.upper()}"+ )+ )+ ]+ )def health_check():diff --git a/python/proto/__init__.py b/python/proto/__init__.pynew file mode 100644index 0000000..e69de29diff --git a/python/proto/ax_pb2.py b/python/proto/ax_pb2.pynew file mode 100644index 0000000..718c77e--- /dev/null+++ b/python/proto/ax_pb2.py@@ -0,0 +1,76 @@+# -*- coding: utf-8 -*-+# Generated by the protocol buffer compiler. DO NOT EDIT!+# source: proto/ax.proto+# Protobuf Python Version: 4.25.1+"""Generated protocol buffer code."""+from google.protobuf import descriptor as _descriptor+from google.protobuf import descriptor_pool as _descriptor_pool+from google.protobuf import symbol_database as _symbol_database+from google.protobuf.internal import builder as _builder+# @@protoc_insertion_point(imports)++_sym_db = _symbol_database.Default()+++from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2+from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2+from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2+++DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0eproto/ax.proto\x12\x05proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\x19google/protobuf/any.proto\"2\n\x0eProcessRequest\x12 \n\x08\x63ontents\x18\x01 \x03(\x0b\x32\x0e.proto.Content\"^\n\x0fProcessResponse\x12\x15\n\rcheckpoint_id\x18\x01 \x01(\t\x12 \n\x08\x63ontents\x18\x02 \x03(\x0b\x32\x0e.proto.Content\x12\x12\n\nfrom_cache\x18\x03 \x01(\x08\"-\n\x0bTextContent\x12\x0c\n\x04text\x18\x03 \x01(\tJ\x04\x08\x01\x10\x02J\x04\x08\x02\x10\x03R\x04type\"$\n\x10\x41pprovalDecision\x12\x10\n\x08\x61pproved\x18\x01 \x01(\x08\"1\n\x0f\x44\x65\x63lineDecision\x12\x10\n\x08\x64\x65\x63lined\x18\x01 \x01(\x08J\x04\x08\x02\x10\x03R\x06reason\"\xa9\x01\n\x13\x43onfirmationContent\x12\n\n\x02id\x18\x03 \x01(\t\x12\x10\n\x08question\x18\x04 \x01(\t\x12+\n\x08\x61pproval\x18\x05 \x01(\x0b\x32\x17.proto.ApprovalDecisionH\x00\x12)\n\x07\x64\x65\x63line\x18\x06 \x01(\x0b\x32\x16.proto.DeclineDecisionH\x00\x42\n\n\x08\x64\x65\x63isionJ\x04\x08\x01\x10\x02J\x04\x08\x02\x10\x03R\x04type\"q\n\x13\x46unctionCallContent\x12\x0c\n\x04name\x18\x01 \x01(\t\x12%\n\x04\x61rgs\x18\x02 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\n\n\x02id\x18\x03 \x01(\t\x12\x19\n\x11thought_signature\x18\x04 \x01(\x0c\"^\n\x17\x46unctionResponseContent\x12\x0c\n\x04name\x18\x01 \x01(\t\x12)\n\x08response\x18\x02 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\n\n\x02id\x18\x03 \x01(\t\"\xff\x01\n\x07\x43ontent\x12\"\n\x04text\x18\n \x01(\x0b\x32\x12.proto.TextContentH\x00\x12\x32\n\x0c\x63onfirmation\x18\x1a \x01(\x0b\x32\x1a.proto.ConfirmationContentH\x00\x12\x33\n\rfunction_call\x18\x1b \x01(\x0b\x32\x1a.proto.FunctionCallContentH\x00\x12;\n\x11\x66unction_response\x18\x1c \x01(\x0b\x32\x1e.proto.FunctionResponseContentH\x00\x12\r\n\x04role\x18\xe8\x07 \x01(\tB\t\n\x07\x63ontentJ\x04\x08\x01\x10\x05J\x04\x08\x06\x10\nJ\x04\x08\x0b\x10\x1a\"\xc0\x01\n\x0e\x45xecutionEvent\x12\x0f\n\x07task_id\x18\x02 \x01(\t\x12\x10\n\x08\x61gent_id\x18\x03 \x01(\t\x12\x1e\n\x06inputs\x18\x04 \x03(\x0b\x32\x0e.proto.Content\x12\x1f\n\x07outputs\x18\x05 \x03(\x0b\x32\x0e.proto.Content\x12\x1b\n\x05state\x18\x06 \x01(\x0e\x32\x0c.proto.State\x12-\n\ttimestamp\x18\x07 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\x14\n\x12HealthCheckRequest\"7\n\x13HealthCheckResponse\x12\x0f\n\x07healthy\x18\x01 \x01(\x08\x12\x0f\n\x07message\x18\x02 \x01(\t\"w\n\x0b\x45xecRequest\x12\n\n\x02id\x18\x01 \x01(\t\x12\x10\n\x08\x61gent_id\x18\x02 \x01(\t\x12*\n\x0c\x61gent_config\x18\x03 \x01(\x0b\x32\x14.google.protobuf.Any\x12\x1e\n\x06inputs\x18\x04 \x03(\x0b\x32\x0e.proto.Content\"L\n\x0c\x45xecResponse\x12\x1f\n\x07outputs\x18\x01 \x03(\x0b\x32\x0e.proto.Content\x12\x1b\n\x05state\x18\x02 \x01(\x0e\x32\x0c.proto.State\"I\n\x0b\x46orkRequest\x12\x0e\n\x06src_id\x18\x01 \x01(\t\x12\x19\n\x11src_checkpoint_id\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65st_id\x18\x03 \x01(\t\"\x1e\n\x0c\x46orkResponse\x12\x0e\n\x06new_id\x18\x01 \x01(\t\"$\n\x11RemoteAgentConfig\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x01(\t\"\xef\x01\n\x14RegisterAgentRequest\x12\x10\n\x08\x61gent_id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x03 \x01(\t\x12;\n\x08metadata\x18\x04 \x03(\x0b\x32).proto.RegisterAgentRequest.MetadataEntry\x12*\n\x06remote\x18\x05 \x01(\x0b\x32\x18.proto.RemoteAgentConfigH\x00\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42\x08\n\x06\x63onfig\"\x17\n\x15RegisterAgentResponse*X\n\x05State\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x11\n\rSTATE_PENDING\x10\x01\x12\x10\n\x0cSTATE_FAILED\x10\x02\x12\x13\n\x0fSTATE_COMPLETED\x10\x03\x32\x92\x01\n\x0c\x41gentService\x12<\n\x07Process\x12\x15.proto.ProcessRequest\x1a\x16.proto.ProcessResponse(\x01\x30\x01\x12\x44\n\x0bHealthCheck\x12\x19.proto.HealthCheckRequest\x1a\x1a.proto.HealthCheckResponse2\xbb\x01\n\tAXService\x12\x31\n\x04\x45xec\x12\x12.proto.ExecRequest\x1a\x13.proto.ExecResponse0\x01\x12/\n\x04\x46ork\x12\x12.proto.ForkRequest\x1a\x13.proto.ForkResponse\x12J\n\rRegisterAgent\x12\x1b.proto.RegisterAgentRequest\x1a\x1c.proto.RegisterAgentResponseB\x1cZ\x1agithub.com/google/ax/protob\x06proto3')++_globals = globals()+_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)+_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'proto.ax_pb2', _globals)+if _descriptor._USE_C_DESCRIPTORS == False:+ _globals['DESCRIPTOR']._options = None+ _globals['DESCRIPTOR']._serialized_options = b'Z\032github.com/google/ax/proto'+ _globals['_REGISTERAGENTREQUEST_METADATAENTRY']._options = None+ _globals['_REGISTERAGENTREQUEST_METADATAENTRY']._serialized_options = b'8\001'+ _globals['_STATE']._serialized_start=1925+ _globals['_STATE']._serialized_end=2013+ _globals['_PROCESSREQUEST']._serialized_start=115+ _globals['_PROCESSREQUEST']._serialized_end=165+ _globals['_PROCESSRESPONSE']._serialized_start=167+ _globals['_PROCESSRESPONSE']._serialized_end=261+ _globals['_TEXTCONTENT']._serialized_start=263+ _globals['_TEXTCONTENT']._serialized_end=308+ _globals['_APPROVALDECISION']._serialized_start=310+ _globals['_APPROVALDECISION']._serialized_end=346+ _globals['_DECLINEDECISION']._serialized_start=348+ _globals['_DECLINEDECISION']._serialized_end=397+ _globals['_CONFIRMATIONCONTENT']._serialized_start=400+ _globals['_CONFIRMATIONCONTENT']._serialized_end=569+ _globals['_FUNCTIONCALLCONTENT']._serialized_start=571+ _globals['_FUNCTIONCALLCONTENT']._serialized_end=684+ _globals['_FUNCTIONRESPONSECONTENT']._serialized_start=686+ _globals['_FUNCTIONRESPONSECONTENT']._serialized_end=780+ _globals['_CONTENT']._serialized_start=783+ _globals['_CONTENT']._serialized_end=1038+ _globals['_EXECUTIONEVENT']._serialized_start=1041+ _globals['_EXECUTIONEVENT']._serialized_end=1233+ _globals['_HEALTHCHECKREQUEST']._serialized_start=1235+ _globals['_HEALTHCHECKREQUEST']._serialized_end=1255+ _globals['_HEALTHCHECKRESPONSE']._serialized_start=1257+ _globals['_HEALTHCHECKRESPONSE']._serialized_end=1312+ _globals['_EXECREQUEST']._serialized_start=1314+ _globals['_EXECREQUEST']._serialized_end=1433+ _globals['_EXECRESPONSE']._serialized_start=1435+ _globals['_EXECRESPONSE']._serialized_end=1511+ _globals['_FORKREQUEST']._serialized_start=1513+ _globals['_FORKREQUEST']._serialized_end=1586+ _globals['_FORKRESPONSE']._serialized_start=1588+ _globals['_FORKRESPONSE']._serialized_end=1618+ _globals['_REMOTEAGENTCONFIG']._serialized_start=1620+ _globals['_REMOTEAGENTCONFIG']._serialized_end=1656+ _globals['_REGISTERAGENTREQUEST']._serialized_start=1659+ _globals['_REGISTERAGENTREQUEST']._serialized_end=1898+ _globals['_REGISTERAGENTREQUEST_METADATAENTRY']._serialized_start=1841+ _globals['_REGISTERAGENTREQUEST_METADATAENTRY']._serialized_end=1888+ _globals['_REGISTERAGENTRESPONSE']._serialized_start=1900+ _globals['_REGISTERAGENTRESPONSE']._serialized_end=1923+ _globals['_AGENTSERVICE']._serialized_start=2016+ _globals['_AGENTSERVICE']._serialized_end=2162+ _globals['_AXSERVICE']._serialized_start=2165+ _globals['_AXSERVICE']._serialized_end=2352+# @@protoc_insertion_point(module_scope)diff --git a/python/proto/ax_pb2_grpc.py b/python/proto/ax_pb2_grpc.pynew file mode 100644index 0000000..bbb32f8--- /dev/null+++ b/python/proto/ax_pb2_grpc.py@@ -0,0 +1,238 @@+# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!+"""Client and server classes corresponding to protobuf-defined services."""+import grpc++from proto import ax_pb2 as proto_dot_ax__pb2+++class AgentServiceStub(object):+ """AgentService defines the gRPC service for agent communication+ """++ def __init__(self, channel):+ """Constructor.++ Args:+ channel: A grpc.Channel.+ """+ self.Process = channel.stream_stream(+ '/proto.AgentService/Process',+ request_serializer=proto_dot_ax__pb2.ProcessRequest.SerializeToString,+ response_deserializer=proto_dot_ax__pb2.ProcessResponse.FromString,+ )+ self.HealthCheck = channel.unary_unary(+ '/proto.AgentService/HealthCheck',+ request_serializer=proto_dot_ax__pb2.HealthCheckRequest.SerializeToString,+ response_deserializer=proto_dot_ax__pb2.HealthCheckResponse.FromString,+ )+++class AgentServiceServicer(object):+ """AgentService defines the gRPC service for agent communication+ """++ def Process(self, request_iterator, context):+ """Process handles bidirectional streaming of content between controller and agent+ """+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)+ context.set_details('Method not implemented!')+ raise NotImplementedError('Method not implemented!')++ def HealthCheck(self, request, context):+ """HealthCheck checks if the agent is healthy and responsive+ """+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)+ context.set_details('Method not implemented!')+ raise NotImplementedError('Method not implemented!')+++def add_AgentServiceServicer_to_server(servicer, server):+ rpc_method_handlers = {+ 'Process': grpc.stream_stream_rpc_method_handler(+ servicer.Process,+ request_deserializer=proto_dot_ax__pb2.ProcessRequest.FromString,+ response_serializer=proto_dot_ax__pb2.ProcessResponse.SerializeToString,+ ),+ 'HealthCheck': grpc.unary_unary_rpc_method_handler(+ servicer.HealthCheck,+ request_deserializer=proto_dot_ax__pb2.HealthCheckRequest.FromString,+ response_serializer=proto_dot_ax__pb2.HealthCheckResponse.SerializeToString,+ ),+ }+ generic_handler = grpc.method_handlers_generic_handler(+ 'proto.AgentService', rpc_method_handlers)+ server.add_generic_rpc_handlers((generic_handler,))+++ # This class is part of an EXPERIMENTAL API.+class AgentService(object):+ """AgentService defines the gRPC service for agent communication+ """++ @staticmethod+ def Process(request_iterator,+ target,+ options=(),+ channel_credentials=None,+ call_credentials=None,+ insecure=False,+ compression=None,+ wait_for_ready=None,+ timeout=None,+ metadata=None):+ return grpc.experimental.stream_stream(request_iterator, target, '/proto.AgentService/Process',+ proto_dot_ax__pb2.ProcessRequest.SerializeToString,+ proto_dot_ax__pb2.ProcessResponse.FromString,+ options, channel_credentials,+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)++ @staticmethod+ def HealthCheck(request,+ target,+ options=(),+ channel_credentials=None,+ call_credentials=None,+ insecure=False,+ compression=None,+ wait_for_ready=None,+ timeout=None,+ metadata=None):+ return grpc.experimental.unary_unary(request, target, '/proto.AgentService/HealthCheck',+ proto_dot_ax__pb2.HealthCheckRequest.SerializeToString,+ proto_dot_ax__pb2.HealthCheckResponse.FromString,+ options, channel_credentials,+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)+++class AXServiceStub(object):+ """AXService defines the gRPC service for AX operations+ """++ def __init__(self, channel):+ """Constructor.++ Args:+ channel: A grpc.Channel.+ """+ self.Exec = channel.unary_stream(+ '/proto.AXService/Exec',+ request_serializer=proto_dot_ax__pb2.ExecRequest.SerializeToString,+ response_deserializer=proto_dot_ax__pb2.ExecResponse.FromString,+ )+ self.Fork = channel.unary_unary(+ '/proto.AXService/Fork',+ request_serializer=proto_dot_ax__pb2.ForkRequest.SerializeToString,+ response_deserializer=proto_dot_ax__pb2.ForkResponse.FromString,+ )+ self.RegisterAgent = channel.unary_unary(+ '/proto.AXService/RegisterAgent',+ request_serializer=proto_dot_ax__pb2.RegisterAgentRequest.SerializeToString,+ response_deserializer=proto_dot_ax__pb2.RegisterAgentResponse.FromString,+ )+++class AXServiceServicer(object):+ """AXService defines the gRPC service for AX operations+ """++ def Exec(self, request, context):+ """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.+ """+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)+ context.set_details('Method not implemented!')+ raise NotImplementedError('Method not implemented!')++ def Fork(self, request, context):+ """Fork forks an event log from a specific checkpoint.+ """+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)+ context.set_details('Method not implemented!')+ raise NotImplementedError('Method not implemented!')++ def RegisterAgent(self, request, context):+ """RegisterAgent registers a new agent with the controller+ """+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)+ context.set_details('Method not implemented!')+ raise NotImplementedError('Method not implemented!')+++def add_AXServiceServicer_to_server(servicer, server):+ rpc_method_handlers = {+ 'Exec': grpc.unary_stream_rpc_method_handler(+ servicer.Exec,+ request_deserializer=proto_dot_ax__pb2.ExecRequest.FromString,+ response_serializer=proto_dot_ax__pb2.ExecResponse.SerializeToString,+ ),+ 'Fork': grpc.unary_unary_rpc_method_handler(+ servicer.Fork,+ request_deserializer=proto_dot_ax__pb2.ForkRequest.FromString,+ response_serializer=proto_dot_ax__pb2.ForkResponse.SerializeToString,+ ),+ 'RegisterAgent': grpc.unary_unary_rpc_method_handler(+ servicer.RegisterAgent,+ request_deserializer=proto_dot_ax__pb2.RegisterAgentRequest.FromString,+ response_serializer=proto_dot_ax__pb2.RegisterAgentResponse.SerializeToString,+ ),+ }+ generic_handler = grpc.method_handlers_generic_handler(+ 'proto.AXService', rpc_method_handlers)+ server.add_generic_rpc_handlers((generic_handler,))+++ # This class is part of an EXPERIMENTAL API.+class AXService(object):+ """AXService defines the gRPC service for AX operations+ """++ @staticmethod+ def Exec(request,+ target,+ options=(),+ channel_credentials=None,+ call_credentials=None,+ insecure=False,+ compression=None,+ wait_for_ready=None,+ timeout=None,+ metadata=None):+ return grpc.experimental.unary_stream(request, target, '/proto.AXService/Exec',+ proto_dot_ax__pb2.ExecRequest.SerializeToString,+ proto_dot_ax__pb2.ExecResponse.FromString,+ options, channel_credentials,+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)++ @staticmethod+ def Fork(request,+ target,+ options=(),+ channel_credentials=None,+ call_credentials=None,+ insecure=False,+ compression=None,+ wait_for_ready=None,+ timeout=None,+ metadata=None):+ return grpc.experimental.unary_unary(request, target, '/proto.AXService/Fork',+ proto_dot_ax__pb2.ForkRequest.SerializeToString,+ proto_dot_ax__pb2.ForkResponse.FromString,+ options, channel_credentials,+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)++ @staticmethod+ def RegisterAgent(request,+ target,+ options=(),+ channel_credentials=None,+ call_credentials=None,+ insecure=False,+ compression=None,+ wait_for_ready=None,+ timeout=None,+ metadata=None):+ return grpc.experimental.unary_unary(request, target, '/proto.AXService/RegisterAgent',+ proto_dot_ax__pb2.RegisterAgentRequest.SerializeToString,+ proto_dot_ax__pb2.RegisterAgentResponse.FromString,+ options, channel_credentials,+ insecure, call_credentials, compression, wait_for_ready, timeout, metadata)