meshagent-cli 0.7.0__py3-none-any.whl → 0.21.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. meshagent/cli/agent.py +15 -11
  2. meshagent/cli/api_keys.py +4 -4
  3. meshagent/cli/async_typer.py +52 -4
  4. meshagent/cli/call.py +12 -8
  5. meshagent/cli/chatbot.py +1007 -129
  6. meshagent/cli/cli.py +21 -20
  7. meshagent/cli/cli_mcp.py +92 -28
  8. meshagent/cli/cli_secrets.py +10 -10
  9. meshagent/cli/common_options.py +19 -4
  10. meshagent/cli/containers.py +164 -16
  11. meshagent/cli/database.py +997 -0
  12. meshagent/cli/developer.py +3 -3
  13. meshagent/cli/exec.py +22 -6
  14. meshagent/cli/helper.py +62 -11
  15. meshagent/cli/helpers.py +66 -9
  16. meshagent/cli/host.py +37 -0
  17. meshagent/cli/mailbot.py +1004 -40
  18. meshagent/cli/mailboxes.py +223 -0
  19. meshagent/cli/meeting_transcriber.py +10 -4
  20. meshagent/cli/messaging.py +7 -7
  21. meshagent/cli/multi.py +402 -0
  22. meshagent/cli/oauth2.py +44 -21
  23. meshagent/cli/participant_token.py +5 -3
  24. meshagent/cli/port.py +70 -0
  25. meshagent/cli/queue.py +2 -2
  26. meshagent/cli/room.py +20 -212
  27. meshagent/cli/rooms.py +214 -0
  28. meshagent/cli/services.py +32 -23
  29. meshagent/cli/sessions.py +5 -5
  30. meshagent/cli/storage.py +5 -5
  31. meshagent/cli/task_runner.py +770 -0
  32. meshagent/cli/version.py +1 -1
  33. meshagent/cli/voicebot.py +502 -76
  34. meshagent/cli/webhook.py +7 -7
  35. meshagent/cli/worker.py +1327 -0
  36. {meshagent_cli-0.7.0.dist-info → meshagent_cli-0.21.0.dist-info}/METADATA +13 -13
  37. meshagent_cli-0.21.0.dist-info/RECORD +44 -0
  38. meshagent_cli-0.7.0.dist-info/RECORD +0 -36
  39. {meshagent_cli-0.7.0.dist-info → meshagent_cli-0.21.0.dist-info}/WHEEL +0 -0
  40. {meshagent_cli-0.7.0.dist-info → meshagent_cli-0.21.0.dist-info}/entry_points.txt +0 -0
  41. {meshagent_cli-0.7.0.dist-info → meshagent_cli-0.21.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1327 @@
1
+ import typer
2
+ from rich import print
3
+ from typing import Annotated, Optional, List, Type
4
+ from pathlib import Path
5
+ import logging
6
+
7
+ from meshagent.tools.storage import StorageToolkitBuilder
8
+
9
+ from meshagent.cli import async_typer
10
+ from meshagent.cli.common_options import ProjectIdOption, RoomOption
11
+ from meshagent.cli.helper import (
12
+ get_client,
13
+ resolve_project_id,
14
+ resolve_room,
15
+ resolve_key,
16
+ cleanup_args,
17
+ )
18
+
19
+ from meshagent.api import (
20
+ ParticipantToken,
21
+ RoomClient,
22
+ WebSocketClientProtocol,
23
+ ApiScope,
24
+ RequiredToolkit,
25
+ RequiredSchema,
26
+ RoomException,
27
+ )
28
+
29
+ from meshagent.api.helpers import meshagent_base_url, websocket_room_url
30
+
31
+ from meshagent.agents.config import RulesConfig
32
+ from meshagent.tools import Toolkit
33
+ from meshagent.tools.storage import StorageToolkit
34
+ from meshagent.tools.database import DatabaseToolkitBuilder, DatabaseToolkitConfig
35
+ from meshagent.tools.datetime import DatetimeToolkit
36
+ from meshagent.tools.uuid import UUIDToolkit
37
+ from meshagent.openai import OpenAIResponsesAdapter
38
+
39
+
40
+ # Your Worker base (the one you pasted) + adapters
41
+ from meshagent.agents.worker import Worker # adjust import
42
+ from meshagent.agents.adapter import LLMAdapter, ToolResponseAdapter # adjust import
43
+
44
+ from meshagent.openai.tools.responses_adapter import (
45
+ WebSearchToolkitBuilder,
46
+ MCPToolkitBuilder,
47
+ WebSearchTool,
48
+ ShellConfig,
49
+ ApplyPatchConfig,
50
+ ApplyPatchTool,
51
+ ApplyPatchToolkitBuilder,
52
+ ShellToolkitBuilder,
53
+ ShellTool,
54
+ LocalShellToolkitBuilder,
55
+ LocalShellTool,
56
+ ImageGenerationToolkitBuilder,
57
+ ImageGenerationTool,
58
+ )
59
+
60
+ from meshagent.cli.host import get_service, run_services, get_deferred, service_specs
61
+ from meshagent.api.specs.service import AgentSpec, ANNOTATION_AGENT_TYPE
62
+
63
+ import yaml
64
+
65
+ import shlex
66
+ import sys
67
+
68
+ from meshagent.api.client import ConflictError
69
+
70
+ logger = logging.getLogger("worker_cli")
71
+
72
+ app = async_typer.AsyncTyper(help="Join a worker agent to a room")
73
+
74
+
75
+ def build_worker(
76
+ *,
77
+ WorkerBase: Type[Worker],
78
+ model: str,
79
+ agent_name: str,
80
+ rule: List[str],
81
+ toolkit: List[str],
82
+ schema: List[str],
83
+ queue: str,
84
+ title: Optional[str] = None,
85
+ description: Optional[str] = None,
86
+ tool_adapter: Optional[ToolResponseAdapter] = None,
87
+ toolkits: Optional[list[Toolkit]] = None,
88
+ rules_file: Optional[str] = None,
89
+ room_rules_paths: list[str] | None = None,
90
+ # thread/tool controls (mirrors mailbot)
91
+ image_generation: Optional[str] = None,
92
+ local_shell: Optional[str] = None,
93
+ shell: Optional[str] = None,
94
+ apply_patch: Optional[str] = None,
95
+ web_search: Optional[str] = None,
96
+ mcp: Optional[str] = None,
97
+ storage: Optional[str] = None,
98
+ working_directory: Optional[str] = None,
99
+ require_image_generation: Optional[str] = None,
100
+ require_local_shell: bool = False,
101
+ require_web_search: bool = False,
102
+ require_apply_patch: bool = False,
103
+ require_shell: bool = False,
104
+ require_storage: bool = False,
105
+ require_read_only_storage: bool = False,
106
+ require_time: bool = True,
107
+ require_uuid: bool = False,
108
+ database_namespace: Optional[list[str]] = None,
109
+ require_table_read: list[str] | None = None,
110
+ require_table_write: list[str] | None = None,
111
+ require_computer_use: bool,
112
+ toolkit_name: Optional[str] = None,
113
+ skill_dirs: Optional[list[str]] = None,
114
+ shell_image: Optional[str] = None,
115
+ log_llm_requests: Optional[bool] = None,
116
+ ):
117
+ """
118
+ Returns a Worker subclass
119
+ """
120
+
121
+ requirements: list = []
122
+ if require_table_read is None:
123
+ require_table_read = []
124
+ if require_table_write is None:
125
+ require_table_write = []
126
+ if toolkits is None:
127
+ toolkits = []
128
+
129
+ for t in toolkit:
130
+ requirements.append(RequiredToolkit(name=t))
131
+ for s in schema:
132
+ requirements.append(RequiredSchema(name=s))
133
+
134
+ # merge in rules file contents
135
+ if rules_file is not None:
136
+ try:
137
+ with open(Path(rules_file).resolve(), "r") as f:
138
+ rule.extend(f.read().splitlines())
139
+ except FileNotFoundError:
140
+ print(f"[yellow]rules file not found at {rules_file}[/yellow]")
141
+
142
+ if require_computer_use:
143
+ llm_adapter: LLMAdapter = OpenAIResponsesAdapter(
144
+ model=model,
145
+ response_options={
146
+ "reasoning": {"summary": "concise"},
147
+ "truncation": "auto",
148
+ },
149
+ log_requests=log_llm_requests,
150
+ )
151
+ else:
152
+ llm_adapter: LLMAdapter = OpenAIResponsesAdapter(
153
+ model=model,
154
+ log_requests=log_llm_requests,
155
+ )
156
+
157
+ class CustomWorker(WorkerBase):
158
+ def __init__(self):
159
+ super().__init__(
160
+ llm_adapter=llm_adapter,
161
+ tool_adapter=tool_adapter,
162
+ name=agent_name,
163
+ requires=requirements,
164
+ toolkits=toolkits,
165
+ queue=queue,
166
+ title=title or agent_name,
167
+ description=description,
168
+ rules=rule if len(rule) > 0 else None,
169
+ toolkit_name=toolkit_name,
170
+ skill_dirs=skill_dirs,
171
+ )
172
+ self._room_rules_paths = room_rules_paths or []
173
+
174
+ async def start(self, *, room: RoomClient):
175
+ print(
176
+ "[bold green]Worker connected. It will consume queue messages.[/bold green]"
177
+ )
178
+ await super().start(room=room)
179
+ if room_rules_paths is not None:
180
+ for p in room_rules_paths:
181
+ await self._load_room_rules(path=p)
182
+
183
+ async def get_rules(self):
184
+ rules = [*await super().get_rules()]
185
+ for p in self._room_rules_paths:
186
+ rules.extend(await self._load_room_rules(path=p))
187
+ return rules
188
+
189
+ async def _load_room_rules(self, *, path: str):
190
+ rules: list[str] = []
191
+ try:
192
+ room_rules = await self.room.storage.download(path=path)
193
+ rules_txt = room_rules.data.decode()
194
+ rules_config = RulesConfig.parse(rules_txt)
195
+ if rules_config.rules is not None:
196
+ rules.extend(rules_config.rules)
197
+
198
+ except RoomException:
199
+ # initialize rules file if missing (same behavior as mailbot)
200
+ try:
201
+ logger.info("attempting to initialize rules file")
202
+ handle = await self.room.storage.open(path=path, overwrite=False)
203
+ await self.room.storage.write(
204
+ handle=handle,
205
+ data=(
206
+ "# Add rules to this file to customize your worker's behavior. "
207
+ "Lines starting with # will be ignored.\n\n"
208
+ ).encode(),
209
+ )
210
+ await self.room.storage.close(handle=handle)
211
+ except RoomException:
212
+ pass
213
+
214
+ logger.info(
215
+ f"unable to load rules from {path}, continuing with default rules"
216
+ )
217
+ return rules
218
+
219
+ def get_toolkit_builders(self):
220
+ providers = []
221
+
222
+ if image_generation:
223
+ providers.append(ImageGenerationToolkitBuilder())
224
+
225
+ if apply_patch:
226
+ providers.append(ApplyPatchToolkitBuilder())
227
+
228
+ if local_shell:
229
+ providers.append(
230
+ LocalShellToolkitBuilder(
231
+ working_directory=working_directory,
232
+ )
233
+ )
234
+
235
+ if shell:
236
+ providers.append(
237
+ ShellToolkitBuilder(
238
+ working_directory=working_directory,
239
+ image=shell_image,
240
+ )
241
+ )
242
+
243
+ if mcp:
244
+ providers.append(MCPToolkitBuilder())
245
+
246
+ if web_search:
247
+ providers.append(WebSearchToolkitBuilder())
248
+
249
+ if storage:
250
+ providers.append(StorageToolkitBuilder())
251
+
252
+ return providers
253
+
254
+ async def get_message_toolkits(self, *, message: dict):
255
+ """
256
+ Optional hook if your WorkerBase supports thread contexts.
257
+ If not, you can remove this; I left it to mirror mailbot's pattern.
258
+ """
259
+ toolkits_out = await super().get_message_toolkits(message=message)
260
+
261
+ thread_toolkit = Toolkit(name="thread_toolkit", tools=[])
262
+
263
+ if require_local_shell:
264
+ thread_toolkit.tools.append(LocalShellTool())
265
+
266
+ if require_shell:
267
+ thread_toolkit.tools.append(
268
+ ShellTool(
269
+ working_directory=working_directory,
270
+ config=ShellConfig(name="shell"),
271
+ image=shell_image or "python:3.13",
272
+ )
273
+ )
274
+
275
+ if require_apply_patch:
276
+ thread_toolkit.tools.append(
277
+ ApplyPatchTool(
278
+ config=ApplyPatchConfig(name="apply_patch"),
279
+ )
280
+ )
281
+
282
+ if require_image_generation is not None:
283
+ thread_toolkit.tools.append(
284
+ ImageGenerationTool(
285
+ model=require_image_generation,
286
+ partial_images=3,
287
+ )
288
+ )
289
+
290
+ if require_web_search:
291
+ thread_toolkit.tools.append(WebSearchTool())
292
+
293
+ if require_storage:
294
+ thread_toolkit.tools.extend(StorageToolkit().tools)
295
+
296
+ if require_read_only_storage:
297
+ thread_toolkit.tools.extend(StorageToolkit(read_only=True).tools)
298
+
299
+ if len(require_table_read) > 0:
300
+ thread_toolkit.tools.extend(
301
+ (
302
+ await DatabaseToolkitBuilder().make(
303
+ room=self.room,
304
+ model=model,
305
+ config=DatabaseToolkitConfig(
306
+ tables=require_table_read,
307
+ read_only=True,
308
+ namespace=database_namespace,
309
+ ),
310
+ )
311
+ ).tools
312
+ )
313
+
314
+ if len(require_table_write) > 0:
315
+ thread_toolkit.tools.extend(
316
+ (
317
+ await DatabaseToolkitBuilder().make(
318
+ room=self.room,
319
+ model=model,
320
+ config=DatabaseToolkitConfig(
321
+ tables=require_table_write,
322
+ read_only=False,
323
+ namespace=database_namespace,
324
+ ),
325
+ )
326
+ ).tools
327
+ )
328
+
329
+ if require_time:
330
+ thread_toolkit.tools.extend(DatetimeToolkit().tools)
331
+
332
+ if require_uuid:
333
+ thread_toolkit.tools.extend(UUIDToolkit().tools)
334
+
335
+ if require_computer_use:
336
+ from meshagent.computers.agent import ComputerToolkit
337
+
338
+ computer_toolkit = ComputerToolkit(room=self.room, render_screen=None)
339
+
340
+ toolkits_out.append(computer_toolkit)
341
+
342
+ toolkits_out.append(thread_toolkit)
343
+ return toolkits_out
344
+
345
+ return CustomWorker
346
+
347
+
348
+ @app.async_command("join")
349
+ async def join(
350
+ *,
351
+ project_id: ProjectIdOption,
352
+ room: RoomOption,
353
+ role: str = "agent",
354
+ agent_name: Annotated[str, typer.Option(..., help="Name of the worker agent")],
355
+ rule: Annotated[List[str], typer.Option("--rule", "-r", help="a system rule")] = [],
356
+ rules_file: Optional[str] = None,
357
+ require_toolkit: Annotated[
358
+ List[str],
359
+ typer.Option(
360
+ "--require-toolkit", "-rt", help="the name or url of a required toolkit"
361
+ ),
362
+ ] = [],
363
+ require_schema: Annotated[
364
+ List[str],
365
+ typer.Option(
366
+ "--require-schema", "-rs", help="the name or url of a required schema"
367
+ ),
368
+ ] = [],
369
+ toolkit: Annotated[
370
+ List[str],
371
+ typer.Option(
372
+ "--toolkit", "-t", help="the name or url of a required toolkit", hidden=True
373
+ ),
374
+ ] = [],
375
+ schema: Annotated[
376
+ List[str],
377
+ typer.Option(
378
+ "--schema", "-s", help="the name or url of a required schema", hidden=True
379
+ ),
380
+ ] = [],
381
+ model: Annotated[
382
+ str, typer.Option(..., help="Name of the LLM model to use")
383
+ ] = "gpt-5.2",
384
+ require_shell: Annotated[
385
+ Optional[bool],
386
+ typer.Option(..., help="Enable function shell tool calling"),
387
+ ] = False,
388
+ require_local_shell: Annotated[
389
+ Optional[bool], typer.Option(..., help="Enable local shell tool calling")
390
+ ] = False,
391
+ require_web_search: Annotated[
392
+ Optional[bool], typer.Option(..., help="Require web search tool")
393
+ ] = False,
394
+ require_apply_patch: Annotated[
395
+ Optional[bool],
396
+ typer.Option(..., help="Enable apply patch tool calling"),
397
+ ] = False,
398
+ key: Annotated[
399
+ str, typer.Option("--key", help="an api key to sign the token with")
400
+ ] = None,
401
+ queue: Annotated[str, typer.Option(..., help="the queue to consume")],
402
+ toolkit_name: Annotated[
403
+ Optional[str],
404
+ typer.Option(..., help="optional toolkit name to expose worker operations"),
405
+ ] = None,
406
+ room_rules: Annotated[
407
+ List[str],
408
+ typer.Option(
409
+ "--room-rules",
410
+ "-rr",
411
+ help="path(s) in room storage to load rules from",
412
+ ),
413
+ ] = [],
414
+ image_generation: Annotated[
415
+ Optional[str], typer.Option(..., help="Name of an image gen model")
416
+ ] = None,
417
+ local_shell: Annotated[
418
+ Optional[bool], typer.Option(..., help="Enable local shell tool calling")
419
+ ] = False,
420
+ shell: Annotated[
421
+ Optional[bool], typer.Option(..., help="Enable function shell tool calling")
422
+ ] = False,
423
+ apply_patch: Annotated[
424
+ Optional[bool], typer.Option(..., help="Enable apply patch tool")
425
+ ] = False,
426
+ web_search: Annotated[
427
+ Optional[bool], typer.Option(..., help="Enable web search tool calling")
428
+ ] = False,
429
+ mcp: Annotated[
430
+ Optional[bool], typer.Option(..., help="Enable mcp tool calling")
431
+ ] = False,
432
+ storage: Annotated[
433
+ Optional[bool], typer.Option(..., help="Enable storage toolkit")
434
+ ] = False,
435
+ require_storage: Annotated[
436
+ Optional[bool], typer.Option(..., help="Enable storage toolkit")
437
+ ] = False,
438
+ require_read_only_storage: Annotated[
439
+ Optional[bool], typer.Option(..., help="Enable read only storage toolkit")
440
+ ] = False,
441
+ require_time: Annotated[
442
+ bool,
443
+ typer.Option(
444
+ ...,
445
+ help="Enable time/datetime tools",
446
+ ),
447
+ ] = True,
448
+ require_uuid: Annotated[
449
+ bool,
450
+ typer.Option(
451
+ ...,
452
+ help="Enable UUID generation tools",
453
+ ),
454
+ ] = False,
455
+ database_namespace: Annotated[
456
+ Optional[str],
457
+ typer.Option(
458
+ ..., help="Use a specific database namespace (JSON list or dotted)"
459
+ ),
460
+ ] = None,
461
+ require_table_read: Annotated[
462
+ list[str], typer.Option(..., help="Enable table read tools for these tables")
463
+ ] = [],
464
+ require_table_write: Annotated[
465
+ list[str], typer.Option(..., help="Enable table write tools for these tables")
466
+ ] = [],
467
+ require_computer_use: Annotated[
468
+ Optional[bool],
469
+ typer.Option(
470
+ ...,
471
+ help="Enable computer use (requires computer-use-preview model)",
472
+ hidden=True,
473
+ ),
474
+ ] = False,
475
+ title: Annotated[
476
+ Optional[str],
477
+ typer.Option(..., help="a display name for the agent"),
478
+ ] = None,
479
+ description: Annotated[
480
+ Optional[str],
481
+ typer.Option(..., help="a description for the agent"),
482
+ ] = None,
483
+ working_directory: Annotated[
484
+ Optional[str],
485
+ typer.Option(..., help="The default working directory for shell commands"),
486
+ ] = None,
487
+ skill_dir: Annotated[
488
+ list[str],
489
+ typer.Option(..., help="an agent skills directory"),
490
+ ] = [],
491
+ shell_image: Annotated[
492
+ Optional[str],
493
+ typer.Option(..., help="an image tag to use to run shell commands in"),
494
+ ] = None,
495
+ log_llm_requests: Annotated[
496
+ Optional[bool],
497
+ typer.Option(..., help="log all requests to the llm"),
498
+ ] = False,
499
+ ):
500
+ key = await resolve_key(project_id=project_id, key=key)
501
+
502
+ account_client = await get_client()
503
+ try:
504
+ project_id = await resolve_project_id(project_id=project_id)
505
+ room_name = resolve_room(room)
506
+
507
+ token = ParticipantToken(name=agent_name)
508
+ token.add_api_grant(ApiScope.agent_default(tunnels=require_computer_use))
509
+ token.add_role_grant(role=role)
510
+ token.add_room_grant(room_name)
511
+
512
+ jwt = token.to_jwt(api_key=key)
513
+
514
+ print("[bold green]Connecting to room...[/bold green]", flush=True)
515
+ async with RoomClient(
516
+ protocol=WebSocketClientProtocol(
517
+ url=websocket_room_url(
518
+ room_name=room_name, base_url=meshagent_base_url()
519
+ ),
520
+ token=jwt,
521
+ )
522
+ ) as client:
523
+ # Plug in your specific worker implementation here:
524
+ # from meshagent.agents.some_worker import SomeWorker
525
+ # WorkerBase = SomeWorker
526
+ from meshagent.agents.worker import Worker as WorkerBase # default; replace
527
+
528
+ CustomWorker = build_worker(
529
+ WorkerBase=WorkerBase,
530
+ model=model,
531
+ agent_name=agent_name,
532
+ rule=rule,
533
+ toolkit=require_toolkit + toolkit,
534
+ schema=require_schema + schema,
535
+ rules_file=rules_file,
536
+ room_rules_paths=room_rules,
537
+ queue=queue,
538
+ local_shell=local_shell,
539
+ shell=shell,
540
+ apply_patch=apply_patch,
541
+ image_generation=image_generation,
542
+ web_search=web_search,
543
+ mcp=mcp,
544
+ storage=storage,
545
+ require_local_shell=require_local_shell,
546
+ require_web_search=require_web_search,
547
+ require_shell=require_shell,
548
+ require_apply_patch=require_apply_patch,
549
+ toolkit_name=toolkit_name,
550
+ require_storage=require_storage,
551
+ require_read_only_storage=require_read_only_storage,
552
+ require_time=require_time,
553
+ require_uuid=require_uuid,
554
+ require_table_read=require_table_read,
555
+ require_table_write=require_table_write,
556
+ require_computer_use=require_computer_use,
557
+ database_namespace=[database_namespace] if database_namespace else None,
558
+ title=title,
559
+ description=description,
560
+ working_directory=working_directory,
561
+ skill_dirs=skill_dir,
562
+ shell_image=shell_image,
563
+ log_llm_requests=log_llm_requests,
564
+ )
565
+
566
+ worker = CustomWorker()
567
+ await worker.start(room=client)
568
+ try:
569
+ await client.protocol.wait_for_close()
570
+ except KeyboardInterrupt:
571
+ await worker.stop()
572
+
573
+ finally:
574
+ await account_client.close()
575
+
576
+
577
+ @app.async_command("service")
578
+ async def service(
579
+ *,
580
+ agent_name: Annotated[str, typer.Option(..., help="Name of the worker agent")],
581
+ rule: Annotated[List[str], typer.Option("--rule", "-r", help="a system rule")] = [],
582
+ rules_file: Optional[str] = None,
583
+ require_toolkit: Annotated[
584
+ List[str],
585
+ typer.Option(
586
+ "--require-toolkit", "-rt", help="the name or url of a required toolkit"
587
+ ),
588
+ ] = [],
589
+ require_schema: Annotated[
590
+ List[str],
591
+ typer.Option(
592
+ "--require-schema", "-rs", help="the name or url of a required schema"
593
+ ),
594
+ ] = [],
595
+ toolkit: Annotated[
596
+ List[str],
597
+ typer.Option(
598
+ "--toolkit", "-t", help="the name or url of a required toolkit", hidden=True
599
+ ),
600
+ ] = [],
601
+ schema: Annotated[
602
+ List[str],
603
+ typer.Option(
604
+ "--schema", "-s", help="the name or url of a required schema", hidden=True
605
+ ),
606
+ ] = [],
607
+ model: Annotated[
608
+ str,
609
+ typer.Option(..., help="Name of the LLM model to use"),
610
+ ] = "gpt-5.2",
611
+ image_generation: Annotated[
612
+ Optional[str], typer.Option(..., help="Name of an image gen model")
613
+ ] = None,
614
+ require_shell: Annotated[
615
+ Optional[bool],
616
+ typer.Option(..., help="Enable function shell tool calling"),
617
+ ] = False,
618
+ local_shell: Annotated[
619
+ Optional[bool], typer.Option(..., help="Enable local shell tool calling")
620
+ ] = False,
621
+ shell: Annotated[
622
+ Optional[bool], typer.Option(..., help="Enable function shell tool calling")
623
+ ] = False,
624
+ apply_patch: Annotated[
625
+ Optional[bool], typer.Option(..., help="Enable apply patch tool")
626
+ ] = False,
627
+ web_search: Annotated[
628
+ Optional[bool], typer.Option(..., help="Enable web search tool calling")
629
+ ] = False,
630
+ mcp: Annotated[
631
+ Optional[bool], typer.Option(..., help="Enable mcp tool calling")
632
+ ] = False,
633
+ storage: Annotated[
634
+ Optional[bool], typer.Option(..., help="Enable storage toolkit")
635
+ ] = False,
636
+ require_local_shell: Annotated[
637
+ Optional[bool], typer.Option(..., help="Require local shell tool")
638
+ ] = False,
639
+ require_web_search: Annotated[
640
+ Optional[bool], typer.Option(..., help="Require web search tool")
641
+ ] = False,
642
+ require_apply_patch: Annotated[
643
+ Optional[bool],
644
+ typer.Option(..., help="Enable apply patch tool calling"),
645
+ ] = False,
646
+ host: Annotated[
647
+ Optional[str], typer.Option(help="Host to bind the service on")
648
+ ] = None,
649
+ port: Annotated[
650
+ Optional[int], typer.Option(help="Port to bind the service on")
651
+ ] = None,
652
+ path: Annotated[
653
+ Optional[str], typer.Option(help="HTTP path to mount the service at")
654
+ ] = None,
655
+ queue: Annotated[str, typer.Option(..., help="the queue to consume")],
656
+ toolkit_name: Annotated[
657
+ Optional[str], typer.Option(..., help="Toolkit name to expose (optional)")
658
+ ] = None,
659
+ room_rules: Annotated[
660
+ List[str],
661
+ typer.Option(
662
+ "--room-rules",
663
+ "-rr",
664
+ help="Path(s) to rules files inside the room",
665
+ ),
666
+ ] = [],
667
+ require_storage: Annotated[
668
+ Optional[bool], typer.Option(..., help="Require storage toolkit")
669
+ ] = False,
670
+ require_read_only_storage: Annotated[
671
+ Optional[bool], typer.Option(..., help="Require read-only storage toolkit")
672
+ ] = False,
673
+ require_time: Annotated[
674
+ bool,
675
+ typer.Option(
676
+ ...,
677
+ help="Enable time/datetime tools",
678
+ ),
679
+ ] = True,
680
+ require_uuid: Annotated[
681
+ bool,
682
+ typer.Option(
683
+ ...,
684
+ help="Enable UUID generation tools",
685
+ ),
686
+ ] = False,
687
+ database_namespace: Annotated[
688
+ Optional[str],
689
+ typer.Option(..., help="Database namespace (e.g. foo::bar)"),
690
+ ] = None,
691
+ require_table_read: Annotated[
692
+ list[str],
693
+ typer.Option(..., help="Require table read tool for table (repeatable)"),
694
+ ] = [],
695
+ require_table_write: Annotated[
696
+ list[str],
697
+ typer.Option(..., help="Require table write tool for table (repeatable)"),
698
+ ] = [],
699
+ require_computer_use: Annotated[
700
+ Optional[bool],
701
+ typer.Option(
702
+ ...,
703
+ help="Enable computer use (requires computer-use-preview model)",
704
+ hidden=True,
705
+ ),
706
+ ] = False,
707
+ title: Annotated[
708
+ Optional[str],
709
+ typer.Option(..., help="a display name for the agent"),
710
+ ] = None,
711
+ description: Annotated[
712
+ Optional[str],
713
+ typer.Option(..., help="a description for the agent"),
714
+ ] = None,
715
+ working_directory: Annotated[
716
+ Optional[str],
717
+ typer.Option(..., help="The default working directory for shell commands"),
718
+ ] = None,
719
+ skill_dir: Annotated[
720
+ list[str],
721
+ typer.Option(..., help="an agent skills directory"),
722
+ ] = [],
723
+ shell_image: Annotated[
724
+ Optional[str],
725
+ typer.Option(..., help="an image tag to use to run shell commands in"),
726
+ ] = None,
727
+ log_llm_requests: Annotated[
728
+ Optional[bool],
729
+ typer.Option(..., help="log all requests to the llm"),
730
+ ] = False,
731
+ ):
732
+ service = get_service(host=host, port=port)
733
+
734
+ if path is None:
735
+ path = "/agent"
736
+ i = 0
737
+ while service.has_path(path):
738
+ i += 1
739
+ path = f"/agent{i}"
740
+
741
+ # Plug in your specific worker implementation here:
742
+ from meshagent.agents.worker import (
743
+ Worker as WorkerBase,
744
+ ) # replace with your concrete worker class
745
+
746
+ service.agents.append(
747
+ AgentSpec(name=agent_name, annotations={ANNOTATION_AGENT_TYPE: "ChatBot"})
748
+ )
749
+
750
+ service.add_path(
751
+ identity=agent_name,
752
+ path=path,
753
+ cls=build_worker(
754
+ WorkerBase=WorkerBase,
755
+ model=model,
756
+ agent_name=agent_name,
757
+ rule=rule,
758
+ toolkit=require_toolkit + toolkit,
759
+ schema=require_schema + schema,
760
+ rules_file=rules_file,
761
+ room_rules_paths=room_rules,
762
+ queue=queue,
763
+ local_shell=local_shell,
764
+ shell=shell,
765
+ apply_patch=apply_patch,
766
+ image_generation=image_generation,
767
+ web_search=web_search,
768
+ mcp=mcp,
769
+ storage=storage,
770
+ require_shell=require_shell,
771
+ require_apply_patch=require_apply_patch,
772
+ require_local_shell=require_local_shell,
773
+ require_web_search=require_web_search,
774
+ toolkit_name=toolkit_name,
775
+ require_storage=require_storage,
776
+ require_read_only_storage=require_read_only_storage,
777
+ require_time=require_time,
778
+ require_uuid=require_uuid,
779
+ require_table_read=require_table_read,
780
+ require_table_write=require_table_write,
781
+ require_computer_use=require_computer_use,
782
+ database_namespace=[database_namespace] if database_namespace else None,
783
+ title=title,
784
+ description=description,
785
+ working_directory=working_directory,
786
+ skill_dirs=skill_dir,
787
+ shell_image=shell_image,
788
+ log_llm_requests=log_llm_requests,
789
+ ),
790
+ )
791
+
792
+ if not get_deferred():
793
+ await run_services()
794
+
795
+
796
+ @app.async_command("spec")
797
+ async def spec(
798
+ *,
799
+ service_name: Annotated[str, typer.Option("--service-name", help="service name")],
800
+ service_description: Annotated[
801
+ Optional[str], typer.Option("--service-description", help="service description")
802
+ ] = None,
803
+ service_title: Annotated[
804
+ Optional[str],
805
+ typer.Option("--service-title", help="a display name for the service"),
806
+ ] = None,
807
+ agent_name: Annotated[str, typer.Option(..., help="Name of the worker agent")],
808
+ rule: Annotated[List[str], typer.Option("--rule", "-r", help="a system rule")] = [],
809
+ rules_file: Optional[str] = None,
810
+ require_toolkit: Annotated[
811
+ List[str],
812
+ typer.Option(
813
+ "--require-toolkit", "-rt", help="the name or url of a required toolkit"
814
+ ),
815
+ ] = [],
816
+ require_schema: Annotated[
817
+ List[str],
818
+ typer.Option(
819
+ "--require-schema", "-rs", help="the name or url of a required schema"
820
+ ),
821
+ ] = [],
822
+ toolkit: Annotated[
823
+ List[str],
824
+ typer.Option(
825
+ "--toolkit", "-t", help="the name or url of a required toolkit", hidden=True
826
+ ),
827
+ ] = [],
828
+ schema: Annotated[
829
+ List[str],
830
+ typer.Option(
831
+ "--schema", "-s", help="the name or url of a required schema", hidden=True
832
+ ),
833
+ ] = [],
834
+ model: Annotated[
835
+ str,
836
+ typer.Option(..., help="Name of the LLM model to use"),
837
+ ] = "gpt-5.2",
838
+ image_generation: Annotated[
839
+ Optional[str], typer.Option(..., help="Name of an image gen model")
840
+ ] = None,
841
+ require_shell: Annotated[
842
+ Optional[bool],
843
+ typer.Option(..., help="Enable function shell tool calling"),
844
+ ] = False,
845
+ local_shell: Annotated[
846
+ Optional[bool], typer.Option(..., help="Enable local shell tool calling")
847
+ ] = False,
848
+ shell: Annotated[
849
+ Optional[bool], typer.Option(..., help="Enable function shell tool calling")
850
+ ] = False,
851
+ apply_patch: Annotated[
852
+ Optional[bool], typer.Option(..., help="Enable apply patch tool")
853
+ ] = False,
854
+ web_search: Annotated[
855
+ Optional[bool], typer.Option(..., help="Enable web search tool calling")
856
+ ] = False,
857
+ mcp: Annotated[
858
+ Optional[bool], typer.Option(..., help="Enable mcp tool calling")
859
+ ] = False,
860
+ storage: Annotated[
861
+ Optional[bool], typer.Option(..., help="Enable storage toolkit")
862
+ ] = False,
863
+ require_local_shell: Annotated[
864
+ Optional[bool], typer.Option(..., help="Require local shell tool")
865
+ ] = False,
866
+ require_web_search: Annotated[
867
+ Optional[bool], typer.Option(..., help="Require web search tool")
868
+ ] = False,
869
+ require_apply_patch: Annotated[
870
+ Optional[bool],
871
+ typer.Option(..., help="Enable apply patch tool calling"),
872
+ ] = False,
873
+ host: Annotated[
874
+ Optional[str], typer.Option(help="Host to bind the service on")
875
+ ] = None,
876
+ port: Annotated[
877
+ Optional[int], typer.Option(help="Port to bind the service on")
878
+ ] = None,
879
+ path: Annotated[
880
+ Optional[str], typer.Option(help="HTTP path to mount the service at")
881
+ ] = None,
882
+ queue: Annotated[str, typer.Option(..., help="the queue to consume")],
883
+ toolkit_name: Annotated[
884
+ Optional[str], typer.Option(..., help="Toolkit name to expose (optional)")
885
+ ] = None,
886
+ room_rules: Annotated[
887
+ List[str],
888
+ typer.Option(
889
+ "--room-rules",
890
+ "-rr",
891
+ help="Path(s) to rules files inside the room",
892
+ ),
893
+ ] = [],
894
+ require_storage: Annotated[
895
+ Optional[bool], typer.Option(..., help="Require storage toolkit")
896
+ ] = False,
897
+ require_read_only_storage: Annotated[
898
+ Optional[bool], typer.Option(..., help="Require read-only storage toolkit")
899
+ ] = False,
900
+ require_time: Annotated[
901
+ bool,
902
+ typer.Option(
903
+ ...,
904
+ help="Enable time/datetime tools",
905
+ ),
906
+ ] = True,
907
+ require_uuid: Annotated[
908
+ bool,
909
+ typer.Option(
910
+ ...,
911
+ help="Enable UUID generation tools",
912
+ ),
913
+ ] = False,
914
+ database_namespace: Annotated[
915
+ Optional[str],
916
+ typer.Option(..., help="Database namespace (e.g. foo::bar)"),
917
+ ] = None,
918
+ require_table_read: Annotated[
919
+ list[str],
920
+ typer.Option(..., help="Require table read tool for table (repeatable)"),
921
+ ] = [],
922
+ require_table_write: Annotated[
923
+ list[str],
924
+ typer.Option(..., help="Require table write tool for table (repeatable)"),
925
+ ] = [],
926
+ require_computer_use: Annotated[
927
+ Optional[bool],
928
+ typer.Option(
929
+ ...,
930
+ help="Enable computer use (requires computer-use-preview model)",
931
+ hidden=True,
932
+ ),
933
+ ] = False,
934
+ title: Annotated[
935
+ Optional[str],
936
+ typer.Option(..., help="a display name for the agent"),
937
+ ] = None,
938
+ description: Annotated[
939
+ Optional[str],
940
+ typer.Option(..., help="a description for the agent"),
941
+ ] = None,
942
+ working_directory: Annotated[
943
+ Optional[str],
944
+ typer.Option(..., help="The default working directory for shell commands"),
945
+ ] = None,
946
+ skill_dir: Annotated[
947
+ list[str],
948
+ typer.Option(..., help="an agent skills directory"),
949
+ ] = [],
950
+ shell_image: Annotated[
951
+ Optional[str],
952
+ typer.Option(..., help="an image tag to use to run shell commands in"),
953
+ ] = None,
954
+ log_llm_requests: Annotated[
955
+ Optional[bool],
956
+ typer.Option(..., help="log all requests to the llm"),
957
+ ] = False,
958
+ ):
959
+ service = get_service(host=host, port=port)
960
+
961
+ if path is None:
962
+ path = "/agent"
963
+ i = 0
964
+ while service.has_path(path):
965
+ i += 1
966
+ path = f"/agent{i}"
967
+
968
+ # Plug in your specific worker implementation here:
969
+ from meshagent.agents.worker import (
970
+ Worker as WorkerBase,
971
+ ) # replace with your concrete worker class
972
+
973
+ service.agents.append(
974
+ AgentSpec(name=agent_name, annotations={ANNOTATION_AGENT_TYPE: "ChatBot"})
975
+ )
976
+
977
+ service.add_path(
978
+ identity=agent_name,
979
+ path=path,
980
+ cls=build_worker(
981
+ WorkerBase=WorkerBase,
982
+ model=model,
983
+ agent_name=agent_name,
984
+ rule=rule,
985
+ toolkit=require_toolkit + toolkit,
986
+ schema=require_schema + schema,
987
+ rules_file=rules_file,
988
+ room_rules_paths=room_rules,
989
+ queue=queue,
990
+ local_shell=local_shell,
991
+ shell=shell,
992
+ apply_patch=apply_patch,
993
+ image_generation=image_generation,
994
+ web_search=web_search,
995
+ mcp=mcp,
996
+ storage=storage,
997
+ require_shell=require_shell,
998
+ require_apply_patch=require_apply_patch,
999
+ require_local_shell=require_local_shell,
1000
+ require_web_search=require_web_search,
1001
+ toolkit_name=toolkit_name,
1002
+ require_storage=require_storage,
1003
+ require_read_only_storage=require_read_only_storage,
1004
+ require_time=require_time,
1005
+ require_uuid=require_uuid,
1006
+ require_table_read=require_table_read,
1007
+ require_table_write=require_table_write,
1008
+ require_computer_use=require_computer_use,
1009
+ database_namespace=[database_namespace] if database_namespace else None,
1010
+ title=title,
1011
+ description=description,
1012
+ working_directory=working_directory,
1013
+ skill_dirs=skill_dir,
1014
+ shell_image=shell_image,
1015
+ log_llm_requests=log_llm_requests,
1016
+ ),
1017
+ )
1018
+
1019
+ spec = service_specs()[0]
1020
+ spec.metadata.annotations = {
1021
+ "meshagent.service.id": service_name,
1022
+ }
1023
+
1024
+ spec.metadata.name = service_name
1025
+ spec.metadata.description = service_description
1026
+ spec.container.image = (
1027
+ "us-central1-docker.pkg.dev/meshagent-public/images/cli:{SERVER_VERSION}-esgz"
1028
+ )
1029
+ spec.container.command = shlex.join(
1030
+ ["meshagent", "worker", "service", *cleanup_args(sys.argv[2:])]
1031
+ )
1032
+
1033
+ print(yaml.dump(spec.model_dump(mode="json", exclude_none=True), sort_keys=False))
1034
+
1035
+
1036
+ @app.async_command("deploy")
1037
+ async def deploy(
1038
+ *,
1039
+ service_name: Annotated[str, typer.Option("--service-name", help="service name")],
1040
+ service_description: Annotated[
1041
+ Optional[str], typer.Option("--service-description", help="service description")
1042
+ ] = None,
1043
+ service_title: Annotated[
1044
+ Optional[str],
1045
+ typer.Option("--service-title", help="a display name for the service"),
1046
+ ] = None,
1047
+ agent_name: Annotated[str, typer.Option(..., help="Name of the worker agent")],
1048
+ rule: Annotated[List[str], typer.Option("--rule", "-r", help="a system rule")] = [],
1049
+ rules_file: Optional[str] = None,
1050
+ require_toolkit: Annotated[
1051
+ List[str],
1052
+ typer.Option(
1053
+ "--require-toolkit", "-rt", help="the name or url of a required toolkit"
1054
+ ),
1055
+ ] = [],
1056
+ require_schema: Annotated[
1057
+ List[str],
1058
+ typer.Option(
1059
+ "--require-schema", "-rs", help="the name or url of a required schema"
1060
+ ),
1061
+ ] = [],
1062
+ toolkit: Annotated[
1063
+ List[str],
1064
+ typer.Option(
1065
+ "--toolkit", "-t", help="the name or url of a required toolkit", hidden=True
1066
+ ),
1067
+ ] = [],
1068
+ schema: Annotated[
1069
+ List[str],
1070
+ typer.Option(
1071
+ "--schema", "-s", help="the name or url of a required schema", hidden=True
1072
+ ),
1073
+ ] = [],
1074
+ model: Annotated[
1075
+ str,
1076
+ typer.Option(..., help="Name of the LLM model to use"),
1077
+ ] = "gpt-5.2",
1078
+ image_generation: Annotated[
1079
+ Optional[str], typer.Option(..., help="Name of an image gen model")
1080
+ ] = None,
1081
+ require_shell: Annotated[
1082
+ Optional[bool],
1083
+ typer.Option(..., help="Enable function shell tool calling"),
1084
+ ] = False,
1085
+ local_shell: Annotated[
1086
+ Optional[bool], typer.Option(..., help="Enable local shell tool calling")
1087
+ ] = False,
1088
+ shell: Annotated[
1089
+ Optional[bool], typer.Option(..., help="Enable function shell tool calling")
1090
+ ] = False,
1091
+ apply_patch: Annotated[
1092
+ Optional[bool], typer.Option(..., help="Enable apply patch tool")
1093
+ ] = False,
1094
+ web_search: Annotated[
1095
+ Optional[bool], typer.Option(..., help="Enable web search tool calling")
1096
+ ] = False,
1097
+ mcp: Annotated[
1098
+ Optional[bool], typer.Option(..., help="Enable mcp tool calling")
1099
+ ] = False,
1100
+ storage: Annotated[
1101
+ Optional[bool], typer.Option(..., help="Enable storage toolkit")
1102
+ ] = False,
1103
+ require_local_shell: Annotated[
1104
+ Optional[bool], typer.Option(..., help="Require local shell tool")
1105
+ ] = False,
1106
+ require_web_search: Annotated[
1107
+ Optional[bool], typer.Option(..., help="Require web search tool")
1108
+ ] = False,
1109
+ require_apply_patch: Annotated[
1110
+ Optional[bool],
1111
+ typer.Option(..., help="Enable apply patch tool calling"),
1112
+ ] = False,
1113
+ host: Annotated[
1114
+ Optional[str], typer.Option(help="Host to bind the service on")
1115
+ ] = None,
1116
+ port: Annotated[
1117
+ Optional[int], typer.Option(help="Port to bind the service on")
1118
+ ] = None,
1119
+ path: Annotated[
1120
+ Optional[str], typer.Option(help="HTTP path to mount the service at")
1121
+ ] = None,
1122
+ queue: Annotated[str, typer.Option(..., help="the queue to consume")],
1123
+ toolkit_name: Annotated[
1124
+ Optional[str], typer.Option(..., help="Toolkit name to expose (optional)")
1125
+ ] = None,
1126
+ room_rules: Annotated[
1127
+ List[str],
1128
+ typer.Option(
1129
+ "--room-rules",
1130
+ "-rr",
1131
+ help="Path(s) to rules files inside the room",
1132
+ ),
1133
+ ] = [],
1134
+ require_storage: Annotated[
1135
+ Optional[bool], typer.Option(..., help="Require storage toolkit")
1136
+ ] = False,
1137
+ require_read_only_storage: Annotated[
1138
+ Optional[bool], typer.Option(..., help="Require read-only storage toolkit")
1139
+ ] = False,
1140
+ require_time: Annotated[
1141
+ bool,
1142
+ typer.Option(
1143
+ ...,
1144
+ help="Enable time/datetime tools",
1145
+ ),
1146
+ ] = True,
1147
+ require_uuid: Annotated[
1148
+ bool,
1149
+ typer.Option(
1150
+ ...,
1151
+ help="Enable UUID generation tools",
1152
+ ),
1153
+ ] = False,
1154
+ database_namespace: Annotated[
1155
+ Optional[str],
1156
+ typer.Option(..., help="Database namespace (e.g. foo::bar)"),
1157
+ ] = None,
1158
+ require_table_read: Annotated[
1159
+ list[str],
1160
+ typer.Option(..., help="Require table read tool for table (repeatable)"),
1161
+ ] = [],
1162
+ require_table_write: Annotated[
1163
+ list[str],
1164
+ typer.Option(..., help="Require table write tool for table (repeatable)"),
1165
+ ] = [],
1166
+ require_computer_use: Annotated[
1167
+ Optional[bool],
1168
+ typer.Option(
1169
+ ...,
1170
+ help="Enable computer use (requires computer-use-preview model)",
1171
+ hidden=True,
1172
+ ),
1173
+ ] = False,
1174
+ title: Annotated[
1175
+ Optional[str],
1176
+ typer.Option(..., help="a display name for the agent"),
1177
+ ] = None,
1178
+ description: Annotated[
1179
+ Optional[str],
1180
+ typer.Option(..., help="a description for the agent"),
1181
+ ] = None,
1182
+ working_directory: Annotated[
1183
+ Optional[str],
1184
+ typer.Option(..., help="The default working directory for shell commands"),
1185
+ ] = None,
1186
+ skill_dir: Annotated[
1187
+ list[str],
1188
+ typer.Option(..., help="an agent skills directory"),
1189
+ ] = [],
1190
+ shell_image: Annotated[
1191
+ Optional[str],
1192
+ typer.Option(..., help="an image tag to use to run shell commands in"),
1193
+ ] = None,
1194
+ log_llm_requests: Annotated[
1195
+ Optional[bool],
1196
+ typer.Option(..., help="log all requests to the llm"),
1197
+ ] = False,
1198
+ project_id: ProjectIdOption,
1199
+ room: Annotated[
1200
+ Optional[str],
1201
+ typer.Option("--room", help="The name of a room to create the service for"),
1202
+ ] = None,
1203
+ ):
1204
+ project_id = await resolve_project_id(project_id=project_id)
1205
+
1206
+ service = get_service(host=host, port=port)
1207
+
1208
+ if path is None:
1209
+ path = "/agent"
1210
+ i = 0
1211
+ while service.has_path(path):
1212
+ i += 1
1213
+ path = f"/agent{i}"
1214
+
1215
+ # Plug in your specific worker implementation here:
1216
+ from meshagent.agents.worker import (
1217
+ Worker as WorkerBase,
1218
+ ) # replace with your concrete worker class
1219
+
1220
+ service.agents.append(
1221
+ AgentSpec(name=agent_name, annotations={ANNOTATION_AGENT_TYPE: "ChatBot"})
1222
+ )
1223
+
1224
+ service.add_path(
1225
+ identity=agent_name,
1226
+ path=path,
1227
+ cls=build_worker(
1228
+ WorkerBase=WorkerBase,
1229
+ model=model,
1230
+ agent_name=agent_name,
1231
+ rule=rule,
1232
+ toolkit=require_toolkit + toolkit,
1233
+ schema=require_schema + schema,
1234
+ rules_file=rules_file,
1235
+ room_rules_paths=room_rules,
1236
+ queue=queue,
1237
+ local_shell=local_shell,
1238
+ shell=shell,
1239
+ apply_patch=apply_patch,
1240
+ image_generation=image_generation,
1241
+ web_search=web_search,
1242
+ mcp=mcp,
1243
+ storage=storage,
1244
+ require_shell=require_shell,
1245
+ require_apply_patch=require_apply_patch,
1246
+ require_local_shell=require_local_shell,
1247
+ require_web_search=require_web_search,
1248
+ toolkit_name=toolkit_name,
1249
+ require_storage=require_storage,
1250
+ require_read_only_storage=require_read_only_storage,
1251
+ require_time=require_time,
1252
+ require_uuid=require_uuid,
1253
+ require_table_read=require_table_read,
1254
+ require_table_write=require_table_write,
1255
+ require_computer_use=require_computer_use,
1256
+ database_namespace=[database_namespace] if database_namespace else None,
1257
+ title=title,
1258
+ description=description,
1259
+ working_directory=working_directory,
1260
+ skill_dirs=skill_dir,
1261
+ shell_image=shell_image,
1262
+ log_llm_requests=log_llm_requests,
1263
+ ),
1264
+ )
1265
+
1266
+ spec = service_specs()[0]
1267
+ spec.metadata.annotations = {
1268
+ "meshagent.service.id": service_name,
1269
+ }
1270
+
1271
+ spec.metadata.name = service_name
1272
+ spec.metadata.description = service_description
1273
+ spec.container.image = (
1274
+ "us-central1-docker.pkg.dev/meshagent-public/images/cli:{SERVER_VERSION}-esgz"
1275
+ )
1276
+ spec.container.command = shlex.join(
1277
+ ["meshagent", "worker", "service", *cleanup_args(sys.argv[2:])]
1278
+ )
1279
+
1280
+ client = await get_client()
1281
+ try:
1282
+ id = None
1283
+ try:
1284
+ if id is None:
1285
+ if room is None:
1286
+ services = await client.list_services(project_id=project_id)
1287
+ else:
1288
+ services = await client.list_room_services(
1289
+ project_id=project_id, room_name=room
1290
+ )
1291
+
1292
+ for s in services:
1293
+ if s.metadata.name == spec.metadata.name:
1294
+ id = s.id
1295
+
1296
+ if id is None:
1297
+ if room is None:
1298
+ id = await client.create_service(
1299
+ project_id=project_id, service=spec
1300
+ )
1301
+ else:
1302
+ id = await client.create_room_service(
1303
+ project_id=project_id, service=spec, room_name=room
1304
+ )
1305
+
1306
+ else:
1307
+ spec.id = id
1308
+ if room is None:
1309
+ await client.update_service(
1310
+ project_id=project_id, service_id=id, service=spec
1311
+ )
1312
+ else:
1313
+ await client.update_room_service(
1314
+ project_id=project_id,
1315
+ service_id=id,
1316
+ service=spec,
1317
+ room_name=room,
1318
+ )
1319
+
1320
+ except ConflictError:
1321
+ print(f"[red]Service name already in use: {spec.metadata.name}[/red]")
1322
+ raise typer.Exit(code=1)
1323
+ else:
1324
+ print(f"[green]Deployed service:[/] {id}")
1325
+
1326
+ finally:
1327
+ await client.close()