Skip to content

Commit 3c28637

Browse files
feat: enable events compaction in auto agent client
1 parent 333d08e commit 3c28637

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

MaxKernel/auto_agent/agent_client/auto_agent_client.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,35 @@
1414
"dotenv not installed, skipping loading environment variables"
1515
)
1616

17+
from google.adk.apps.app import App
1718
from google.adk.runners import Runner
1819
from google.adk.sessions.in_memory_session_service import InMemorySessionService
1920
from google.genai.types import Content, Part
2021

2122
from auto_agent.agent import root_agent
23+
from auto_agent.config import get_compaction_config
2224

2325
logger = logging.getLogger(__name__)
2426

2527

2628
class AutoAgentClient:
27-
user_id: str
28-
session_id: str
29-
query: str
30-
app_name: str = "auto_agent"
31-
3229
def __init__(
3330
self,
3431
user_id: str,
3532
session_id: str,
3633
query: str,
3734
agent: Optional[Any] = None,
35+
app_name: str = "auto_agent",
36+
events_compaction: bool = False,
3837
):
3938
self.user_id = user_id
4039
self.session_id = session_id
4140
self.query = query
4241
self.agent = agent or root_agent
4342
self.session_service = InMemorySessionService()
4443
self.session = None
44+
self.app_name = app_name
45+
self.events_compaction = events_compaction
4546

4647
async def create_session(
4748
self, initial_state: Optional[dict[str, Any]] = None
@@ -77,9 +78,19 @@ async def run_async(self) -> None:
7778
if not self.session:
7879
await self.create_session()
7980

81+
# Compaction configuration must be passed via an App object
82+
if self.events_compaction:
83+
compaction_config = get_compaction_config()
84+
else:
85+
compaction_config = None
86+
app = App(
87+
name=self.app_name,
88+
root_agent=self.agent,
89+
events_compaction_config=compaction_config,
90+
)
91+
8092
runner = Runner(
81-
app_name=self.app_name,
82-
agent=self.agent,
93+
app=app,
8394
session_service=self.session_service,
8495
)
8596

@@ -124,6 +135,11 @@ def main():
124135
default="client_query.txt",
125136
help="File containing the query to send",
126137
)
138+
parser.add_argument(
139+
"--events_compaction",
140+
action="store_true",
141+
help="Enable event compaction",
142+
)
127143
args = parser.parse_args()
128144

129145
user_id = args.user_id
@@ -132,7 +148,12 @@ def main():
132148
query = read_query_from_file(args.query_file)
133149

134150
# Create client instance
135-
client = AutoAgentClient(user_id, session_id, query)
151+
client = AutoAgentClient(
152+
user_id=user_id,
153+
session_id=session_id,
154+
query=query,
155+
events_compaction=args.events_compaction,
156+
)
136157

137158
logger.info(
138159
f"Generating script for user {user_id} in session {session_id} with query: {query}"

MaxKernel/auto_agent/agent_client/run_batch_agent_call.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def parse_args():
2727
default=2,
2828
help="Maximum number of retries for failed tasks",
2929
)
30+
parser.add_argument(
31+
"--events_compaction",
32+
action="store_true",
33+
help="Enable event compaction",
34+
)
3035
parser.add_argument(
3136
"--log_file", type=str, default=None, help="File to save logs to"
3237
)
@@ -61,6 +66,7 @@ async def process_problem(
6166
data_dir: str,
6267
max_retries: int,
6368
sem: asyncio.Semaphore,
69+
events_compaction: bool = False,
6470
):
6571
async with sem:
6672
problem_dir = os.path.join(data_dir, problem_id)
@@ -88,6 +94,7 @@ async def process_problem(
8894
user_id=user_id,
8995
session_id=session_id,
9096
query=query,
97+
events_compaction=events_compaction,
9198
)
9299

93100
session_file = os.path.join(
@@ -159,7 +166,9 @@ async def main_async(args):
159166
sem = asyncio.Semaphore(args.num_concurrent)
160167

161168
tasks = [
162-
process_problem(problem, args.data_dir, args.max_retries, sem)
169+
process_problem(
170+
problem, args.data_dir, args.max_retries, sem, args.events_compaction
171+
)
163172
for problem in problems
164173
]
165174

MaxKernel/auto_agent/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
# Set events compaction policy to avoid memory overflow
2020
def get_compaction_config():
2121
return EventsCompactionConfig(
22-
token_threshold=200000,
23-
event_retention_size=100,
24-
compaction_interval=1,
22+
token_threshold=300000,
23+
event_retention_size=5,
24+
compaction_interval=0,
2525
overlap_size=0,
2626
)
2727

0 commit comments

Comments
 (0)