-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenclaw_quickstart.py
More file actions
151 lines (132 loc) · 4.35 KB
/
openclaw_quickstart.py
File metadata and controls
151 lines (132 loc) · 4.35 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
Minimal OpenClaw adapter quickstart.
Run: python examples/openclaw_quickstart.py
"""
from __future__ import annotations
import json
import shutil
import sys
import tempfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from forkit.schemas import TaskType
from forkit.sdk import ForkitClient
from forkit_openclaw import OpenClawAdapter
CREATOR = {"name": "Hamza", "organization": "ForkIt"}
def write_plugin(plugin_root: Path) -> None:
(plugin_root / "hooks" / "session-memory").mkdir(parents=True)
(plugin_root / "openclaw.plugin.json").write_text(
json.dumps(
{
"name": "@forkit/openclaw-ops",
"version": "1.0.0",
"type": "module",
"openclaw": {
"extensions": ["./index.ts"],
},
},
indent=2,
),
encoding="utf-8",
)
(plugin_root / "index.ts").write_text(
"""
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
export default definePluginEntry({
id: "ops-plugin",
name: "Ops Plugin",
description: "Adds operational tooling to OpenClaw",
register(api) {
api.registerTool(
{
name: "incident_lookup",
description: "Lookup incidents",
},
{ optional: true },
);
},
});
""".strip(),
encoding="utf-8",
)
(plugin_root / "hooks" / "session-memory" / "HOOK.md").write_text(
"""
---
name: session-memory
description: "Save session summaries"
metadata: { "openclaw": { "events": ["command:new"] } }
---
# Session Memory
""".strip(),
encoding="utf-8",
)
(plugin_root / "hooks" / "session-memory" / "handler.ts").write_text(
"export default async function handler() {}",
encoding="utf-8",
)
def write_config(config_path: Path) -> None:
config_path.write_text(
"""
// OpenClaw gateway config
{
agents: {
defaults: { workspace: "~/.openclaw/workspace" },
entries: {
ops: {
model: "gpt-4.1",
tools: { allow: ["incident_lookup"] },
},
},
},
channels: { matrix: { allowFrom: ["@ops:example.org"] } },
tools: { allow: ["incident_lookup"] },
hooks: { internal: { enabled: true } },
}
""".strip(),
encoding="utf-8",
)
if __name__ == "__main__":
temp_root = Path(tempfile.mkdtemp(prefix="forkit-openclaw-demo-"))
try:
registry_root = temp_root / "registry"
plugin_root = temp_root / "openclaw-ops"
plugin_root.mkdir()
config_path = temp_root / "openclaw.json"
write_plugin(plugin_root)
write_config(config_path)
client = ForkitClient(registry_root=registry_root)
adapter = OpenClawAdapter(client=client)
model_id = client.models.register(
name="openclaw-base-model",
version="1.0.0",
task_type=TaskType.TEXT_GENERATION,
architecture="transformer",
creator=CREATOR,
)
gateway_id = adapter.register_gateway(
config_path,
plugin_roots=[plugin_root],
name="openclaw-ops-gateway",
version="1.0.0",
model_id=model_id,
creator=CREATOR,
system_prompt="Keep operational tools available.",
)
agent = client.agents.get(gateway_id)
plugin_spec = agent.metadata["openclaw"]["agent_spec"]["plugins"][0]
print(
json.dumps(
{
"gateway_id": gateway_id,
"artifact_hash": agent.artifact_hash,
"architecture": agent.architecture.value,
"tool_names": [tool.name for tool in agent.tools],
"plugin_name": plugin_spec["name"],
"channel_names": agent.metadata["openclaw"]["agent_spec"]["channels"],
"hook_names": [hook["name"] for hook in plugin_spec["hooks"]],
},
indent=2,
)
)
finally:
shutil.rmtree(temp_root, ignore_errors=True)