-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathdemo.py
More file actions
91 lines (75 loc) · 3.25 KB
/
demo.py
File metadata and controls
91 lines (75 loc) · 3.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""
Demo script for cheetahclaws.
Requires ANTHROPIC_API_KEY environment variable.
Run:
ANTHROPIC_API_KEY=sk-... python demo.py
"""
import os
import sys
# Add parent path for imports
sys.path.insert(0, os.path.dirname(__file__))
from cc_config import load_config
from context import build_system_prompt
from agent import AgentState, run, TextChunk, ThinkingChunk, ToolStart, ToolEnd, TurnDone, PermissionRequest
def demo():
config = load_config()
if not config["api_key"]:
print("Error: Set ANTHROPIC_API_KEY environment variable")
sys.exit(1)
config["permission_mode"] = "accept-all" # Demo: auto-approve everything
config["verbose"] = True
state = AgentState()
system_prompt = build_system_prompt()
print("=" * 60)
print("DEMO 1: Simple question (no tools)")
print("=" * 60)
_run_demo(state, config, system_prompt,
"What is the time complexity of quicksort? Answer in 2 sentences.")
print("\n" + "=" * 60)
print("DEMO 2: File system exploration (uses Glob + Read tools)")
print("=" * 60)
state2 = AgentState()
_run_demo(state2, config, system_prompt,
"List all Python files in the current directory and show me the first 5 lines of cheetahclaws.py")
print("\n" + "=" * 60)
print("DEMO 3: Code writing (uses Write + Bash tools)")
print("=" * 60)
state3 = AgentState()
_run_demo(state3, config, system_prompt,
"Write a Python function to fibonacci(n) in /tmp/fib.py, then run it to test fib(10)")
print("\n" + "=" * 60)
print("DEMO 4: Multi-turn conversation")
print("=" * 60)
state4 = AgentState()
_run_demo(state4, config, system_prompt,
"What are the tools available to you?")
_run_demo(state4, config, system_prompt,
"Which of those tools would you use to find all TODO comments in a codebase?")
print("\n" + "=" * 60)
print("DEMO 5: Web search")
print("=" * 60)
state5 = AgentState()
_run_demo(state5, config, system_prompt,
"Search the web for 'Python 3.13 new features' and give me a brief summary")
def _run_demo(state: AgentState, config: dict, system_prompt: str, prompt: str):
print(f"\n[USER]: {prompt}\n")
print("[CLAUDE]: ", end="", flush=True)
for event in run(prompt, state, config, system_prompt):
if isinstance(event, TextChunk):
print(event.text, end="", flush=True)
elif isinstance(event, ThinkingChunk):
if config.get("verbose"):
print(f"\033[2m[thinking: {event.text[:100]}]\033[0m", end="", flush=True)
elif isinstance(event, ToolStart):
print(f"\n\033[36m ⚙ {event.name}({list(event.inputs.values())[0] if event.inputs else ''})\033[0m", flush=True)
elif isinstance(event, PermissionRequest):
event.granted = True # Auto-approve in demo
elif isinstance(event, ToolEnd):
result_preview = event.result[:100].replace('\n', '↵')
print(f"\033[32m ✓ → {result_preview}\033[0m", flush=True)
elif isinstance(event, TurnDone):
print(f"\n\033[2m [+{event.input_tokens} in / +{event.output_tokens} out]\033[0m", flush=True)
print()
if __name__ == "__main__":
demo()