Skip to content

Commit 8fe4c9f

Browse files
committed
Improve the CLI
1 parent 4ea3a22 commit 8fe4c9f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

coagent/cli/main.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def jq_filter(data: dict, filter: str) -> str:
2020
return jq.compile(filter).input(data).first()
2121

2222

23-
def print_msg(msg: RawMessage, oneline: bool, filter: str) -> None:
23+
def print_msg(msg: RawMessage | None, oneline: bool, filter: str) -> None:
24+
if msg is None:
25+
return
26+
2427
output = msg.encode()
2528

2629
content = output.get("content")
@@ -35,13 +38,17 @@ def print_msg(msg: RawMessage, oneline: bool, filter: str) -> None:
3538
async def run(
3639
server: str,
3740
auth: str,
38-
agent: str,
41+
address: str,
3942
msg: RawMessage,
4043
stream: bool,
4144
oneline: bool,
4245
filter: str,
4346
):
44-
session_id = uuid.uuid4().hex
47+
parts = address.split(":", 1)
48+
if len(parts) == 2:
49+
agent_type, session_id = parts
50+
else:
51+
agent_type, session_id = parts[0], uuid.uuid4().hex
4552

4653
if server.startswith("nats://"):
4754
runtime = NATSRuntime.from_servers(server)
@@ -51,7 +58,7 @@ async def run(
5158
raise ValueError(f"Unsupported server: {server}")
5259

5360
async with runtime:
54-
addr = Address(name=agent, id=session_id)
61+
addr = Address(name=agent_type, id=session_id)
5562
try:
5663
if not stream:
5764
response = await runtime.channel.publish(
@@ -68,7 +75,9 @@ async def run(
6875
def main():
6976
parser = argparse.ArgumentParser()
7077
parser.add_argument(
71-
"agent", type=str, help="The type of the agent to communicate with."
78+
"address",
79+
type=str,
80+
help="The address of the agent to communicate with. Format: `agent_type[:session_id]`. (e.g. `pong` or `pong:123`)",
7281
)
7382
parser.add_argument(
7483
"-d",
@@ -136,7 +145,7 @@ def main():
136145
run(
137146
args.server,
138147
args.auth,
139-
args.agent,
148+
args.address,
140149
msg,
141150
args.stream,
142151
args.oneline,

0 commit comments

Comments
 (0)