Skip to content

armgit / ax

Public Imported from GitHub
0

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

Go

Take a list of content as inputs

JBD9b2ed22857d7
diff --git a/README.md b/README.md
index 74d839c..8cd0411 100644
--- a/README.md
+++ b/README.md
@@ -384,14 +384,15 @@ Then implement your agent using the framework:
from gar import Agent
import proto.gar_pb2 as pb2
-def process(content):
- """Process incoming content and return response"""
- return pb2.Content(
- role="assistant",
- type="text",
- mimetype="text/plain",
- data=f"Python processed: {content.data.upper()}"
- )
+def process(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: {content.data.upper()}"
+ )
def health_check():
"""Health check function that always returns healthy"""
diff --git a/python/example_agent.py b/python/example_agent.py
index bcd73e9..b8c360e 100644
--- a/python/example_agent.py
+++ b/python/example_agent.py
@@ -9,14 +9,15 @@ from gar import Agent
import proto.gar_pb2 as pb2
-def process(content):
- """Process incoming content and return response"""
- return pb2.Content(
- role="assistant",
- type="text",
- mimetype="text/plain",
- data=f"Python processed: {content.data.upper()}"
- )
+def process(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: {content.data.upper()}"
+ )
def health_check():
diff --git a/python/gar.py b/python/gar.py
index 41e7c83..0ba6675 100644
--- a/python/gar.py
+++ b/python/gar.py
@@ -15,9 +15,10 @@ class Agent:
Agent provides a simple framework for building Python agents.
Usage:
- def process(content):
- return Content(role="assistant", type="text",
- mimetype="text/plain", data=f"Processed: {content.data}")
+ def process(inputs):
+ for content in inputs:
+ yield Content(role="assistant", type="text",
+ mimetype="text/plain", data=f"Processed: {content.data}")
agent = Agent(agent_id="my-agent", process_func=process)
agent.serve(port=50051)
@@ -35,7 +36,7 @@ class Agent:
Args:
agent_id: Unique identifier for this agent
- process_func: Function that processes Content and returns Content
+ process_func: Function that takes a list of Content and yields Content responses
lifecycle_func: Optional function that yields LifecycleEvent objects
health_check_func: Optional function that returns (healthy: bool, message: str, metadata: dict)
"""
@@ -50,8 +51,11 @@ class Agent:
class AgentServicer(pb2_grpc.AgentServiceServicer):
def Process(self, request_iterator, context):
- for content in request_iterator:
- response = agent.process_func(content)
+ # Collect all content into a list
+ inputs = list(request_iterator)
+
+ # Process the list of content
+ for response in agent.process_func(inputs):
if response:
yield response
@@ -132,7 +136,7 @@ def create_agent(
Args:
agent_id: Unique identifier for this agent
- process_func: Function that processes Content and returns Content
+ process_func: Function that takes a list of Content and yields Content responses
lifecycle_func: Optional function that yields LifecycleEvent objects
health_check_func: Optional function that returns (healthy: bool, message: str, metadata: dict)
port: Port to listen on (default: 50051)