-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_shell_skill.py
More file actions
89 lines (70 loc) · 2.79 KB
/
local_shell_skill.py
File metadata and controls
89 lines (70 loc) · 2.79 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
"""Load a Musher skill as a local OpenAI shell skill and use it on this repo.
Requires: pip install openai-agents
"""
import asyncio
from pathlib import Path
from agents import (
Agent,
Runner,
ShellCallOutcome,
ShellCommandOutput,
ShellCommandRequest,
ShellResult,
ShellTool,
)
import musher
# Credentials auto-discovered from MUSHER_API_KEY env var, keyring,
# or credential file. To override: musher.configure(token="your-token")
PROJECT_DIR = Path(__file__).resolve().parents[2]
# WARNING: This executor runs arbitrary shell commands on the local machine.
# It is intended for development and demonstration only. Do not use in
# production without sandboxing and command allowlisting.
class RepoShell:
"""Minimal local shell executor for the OpenAI Agents SDK."""
def __init__(self, cwd: Path) -> None:
self.cwd = cwd
async def __call__(self, request: ShellCommandRequest) -> ShellResult:
outputs: list[ShellCommandOutput] = []
for command in request.data.action.commands:
proc = await asyncio.create_subprocess_shell(
command,
cwd=self.cwd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await proc.communicate()
outputs.append(
ShellCommandOutput(
command=command,
stdout=stdout.decode("utf-8", errors="ignore"),
stderr=stderr.decode("utf-8", errors="ignore"),
outcome=ShellCallOutcome(type="exit", exit_code=proc.returncode),
)
)
return ShellResult(
output=outputs,
max_output_length=request.data.action.max_output_length,
provider_data={"working_directory": str(self.cwd)},
)
async def main() -> None:
bundle = musher.pull("musher-examples/code-review-kit:1.2.0")
skill = bundle.skill("researching-repos")
local = skill.export_openai_local_skill(dest=PROJECT_DIR / ".musher" / "openai" / "skills")
agent = Agent(
name="Repo Research Assistant",
model="gpt-4.1",
instructions="Use the local skill when it helps. Keep the answer concise and actionable.",
tools=[
ShellTool(
executor=RepoShell(PROJECT_DIR),
environment={"type": "local", "skills": [local.to_dict()]},
)
],
)
result = await Runner.run(
agent,
"Use the researching-repos skill to explore this repository and summarize its tech stack, structure, and conventions.",
)
print(result.final_output)
if __name__ == "__main__":
asyncio.run(main())