-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
61 lines (53 loc) · 2.24 KB
/
cli.py
File metadata and controls
61 lines (53 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
cli.py - Headless CLI for the Agentic Wallet SDK.
Usage:
python cli.py "Check my balance" # single command
python cli.py --interactive # REPL
"""
import argparse, asyncio, os, sys
sys.path.insert(0, os.path.dirname(__file__))
async def run_once(instruction, keypair, network, model):
from agent import create_agent
key = os.getenv("OPENROUTER_API_KEY", "")
if not key: print("ERROR: set OPENROUTER_API_KEY"); sys.exit(1)
agent = await create_agent(keypair_path=keypair, network=network,
openrouter_api_key=key, model=model)
try:
r = await agent.run(instruction)
print("\n" + "="*60)
print("RESULT:", r["summary"])
print(f"Iterations: {r.get('iterations')}")
print("="*60)
finally:
await agent.close()
async def repl(keypair, network, model):
from agent import create_agent
key = os.getenv("OPENROUTER_API_KEY", "")
if not key: print("ERROR: set OPENROUTER_API_KEY"); sys.exit(1)
agent = await create_agent(keypair_path=keypair, network=network,
openrouter_api_key=key, model=model)
print(f"\nAgentic Wallet REPL | {agent.wallet.get_public_key()[:20]}... | {network}")
print("Type instruction or q to exit\n")
try:
while True:
try: line = input("wallet> ").strip()
except (EOFError, KeyboardInterrupt): break
if not line: continue
if line.lower() in ("q","quit","exit"): break
r = await agent.run(line)
print(f"\n-> {r['summary']}\n")
finally:
await agent.close()
def main():
p = argparse.ArgumentParser(description="Agentic Wallet CLI")
p.add_argument("instruction", nargs="?", default=None)
p.add_argument("--interactive", action="store_true")
p.add_argument("--keypair", default=None)
p.add_argument("--network", default="devnet", choices=["devnet","mainnet-beta"])
p.add_argument("--model", default="anthropic/claude-3.5-haiku")
a = p.parse_args()
if a.interactive: asyncio.run(repl(a.keypair, a.network, a.model))
elif a.instruction: asyncio.run(run_once(a.instruction, a.keypair, a.network, a.model))
else: p.print_help()
if __name__ == "__main__":
main()