-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (49 loc) · 1.72 KB
/
Copy pathmain.py
File metadata and controls
61 lines (49 loc) · 1.72 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
from __future__ import annotations
import asyncio
import os
from pathlib import Path
import boxlite
from boxlite_kaos import BoxliteKaos
from kaos import reset_current_kaos, set_current_kaos
from kaos.path import KaosPath
from kimi_agent_sdk import prompt
async def main() -> None:
# Step 1: pick a working directory inside the box.
work_dir_path: str = os.getenv("KIMI_WORK_DIR", DEFAULT_WORK_DIR)
# Step 2: choose the image for BoxLite.
image = os.getenv("BOXLITE_IMAGE", DEFAULT_IMAGE)
# Step 3: create a BoxLite box.
runtime = boxlite.Boxlite.default()
box = await runtime.create(boxlite.BoxOptions(image=image))
await box.start()
print(f"Created box: {box.id}")
# Step 4: install BoxLite as the KAOS backend for the SDK.
boxlite_kaos = BoxliteKaos(
box,
cwd=work_dir_path,
home_dir=DEFAULT_HOME_DIR,
)
token = set_current_kaos(boxlite_kaos)
try:
# Step 5: use KaosPath to access the box filesystem.
work_dir: KaosPath = KaosPath(work_dir_path)
await work_dir.mkdir(parents=True, exist_ok=True)
# Step 6: call the high-level prompt API as usual.
async for msg in prompt(
"You are in a BoxLite sandbox. Explore the environment. Try all your tools!",
work_dir=work_dir,
agent_file=AGENT_FILE,
yolo=True,
):
print("─" * 60)
print(msg)
print("─" * 60)
finally:
reset_current_kaos(token)
await box.stop()
DEFAULT_HOME_DIR = "/root"
DEFAULT_WORK_DIR = "/root/kimi-workdir"
DEFAULT_IMAGE = "python:3.12-slim"
AGENT_FILE = Path(__file__).resolve().with_name("agent.yaml")
if __name__ == "__main__":
asyncio.run(main())