mirror of
https://github.com/open-webui/computer.git
synced 2026-11-24 22:37:40 -05:00
refac
This commit is contained in:
1 parent
b94d72f777
commit
fe70685d68
8 files changed
+421
-19
No files matched your search
@@ -50,6 +50,104 @@ PLAN_MODE_PROMPT = (
|
||||
"tools or implementing."
|
||||
)
|
||||
|
||||
SKILLS_CREATE_RE = re.compile(r"^/skills:create(?:\s+(.*))?$", re.IGNORECASE | re.DOTALL)
|
||||
|
||||
COMPUTER_SKILL_AUTHORING_STANDARDS = """\
|
||||
Follow the Computer skill-authoring standards:
|
||||
|
||||
Frontmatter:
|
||||
- name: lowercase-hyphenated, <=64 chars, no spaces.
|
||||
- description: one sentence, <=60 characters, ends with a period. State the
|
||||
capability, not the implementation. Do not repeat the skill name. Avoid
|
||||
marketing words like powerful, comprehensive, seamless, advanced, or robust.
|
||||
Count the characters before saving.
|
||||
- version: 0.1.0.
|
||||
- platforms: declare [macos], [linux], or [windows] only when the skill uses
|
||||
OS-bound primitives. Omit it for portable skills.
|
||||
|
||||
Body section order:
|
||||
1. "# <Human Title>" plus a short intro covering what it does, what it does not
|
||||
do, and important dependency assumptions.
|
||||
2. "## When to Use" with concrete trigger phrases.
|
||||
3. "## Prerequisites" with exact env vars, credentials, install steps, or "None".
|
||||
4. "## How to Run" with the canonical workflow framed through Computer tools.
|
||||
5. "## Quick Reference" with flat commands, routes, files, or APIs.
|
||||
6. "## Procedure" with numbered, copy-paste-exact steps.
|
||||
7. "## Pitfalls" with known limits and failure modes.
|
||||
8. "## Verification" with one focused check that proves the skill works.
|
||||
|
||||
Computer-tool framing:
|
||||
- Reference Computer tools by name in backticks: `read_file`, `list_directory`,
|
||||
`search_files`, `web_search`, `read_url`, `run_command`, `view_skill`,
|
||||
and `manage_skill`.
|
||||
- Frame shell work as "run through `run_command`".
|
||||
- Prefer Computer tools in prose over raw shell utilities when a tool exists:
|
||||
say `read_file` instead of cat/head/tail, `search_files` instead of grep/rg/find,
|
||||
and `read_url` instead of curl-to-scrape.
|
||||
- Third-party CLIs are fine inside procedures or scripts, but explain that the
|
||||
agent invokes them through `run_command`.
|
||||
|
||||
Quality bar:
|
||||
- Prefer exact commands, routes, file paths, function names, config keys, and
|
||||
error text found verbatim in the sources. Do not invent flags, paths, APIs,
|
||||
or behavior.
|
||||
- Keep SKILL.md tight and scannable: about 100 lines for a simple workflow,
|
||||
about 200 for a complex one.
|
||||
- Do not create a router/index/hub skill that only points at other skills.
|
||||
- Put larger reusable scripts in `scripts/`, detailed docs in `references/`,
|
||||
reusable outputs in `templates/`, and binary or visual assets in `assets/`.
|
||||
- New skills default to workspace scope. Do not use scope="global" unless the
|
||||
user explicitly asks for a global skill."""
|
||||
|
||||
|
||||
def _build_skill_create_prompt(user_request: str) -> str:
|
||||
req = (user_request or "").strip()
|
||||
if not req:
|
||||
req = (
|
||||
"the workflow we just went through in this conversation - review the "
|
||||
"steps taken and distill them into a reusable skill"
|
||||
)
|
||||
return (
|
||||
"[/skills:create] The user wants you to create a reusable Computer skill "
|
||||
"from the request below and save it.\n\n"
|
||||
f"THE REQUEST:\n{req}\n\n"
|
||||
"The request is open-ended and may mix SOURCES to gather (directories, "
|
||||
"file paths, URLs, what we just did, pasted notes) and REQUIREMENTS that "
|
||||
"shape the skill (focus, exclusions, scope, naming, style, constraints). "
|
||||
"Treat every part of the request as load-bearing. Prose after a path or "
|
||||
"URL is not incidental; it is authoring guidance. Never fetch the first "
|
||||
"source and ignore the rest.\n\n"
|
||||
"Do this:\n"
|
||||
"1. Gather every source the user named with the tools you already have: "
|
||||
"`read_file`/`search_files`/`list_directory` for local files or directories, "
|
||||
"`web_search`/`read_url` for web sources, the current conversation if they "
|
||||
"refer to what just happened, and pasted text as-is. If scope is ambiguous, "
|
||||
"make a reasonable choice and note it; do not stall.\n"
|
||||
"2. Apply every requirement, focus, and constraint in the request to what "
|
||||
"the skill covers and emphasizes.\n"
|
||||
"3. Author one SKILL.md using the standards below.\n"
|
||||
'4. Save it with manage_skill(action="create", name=..., content=...). '
|
||||
"If the skill needs supporting files, add them after the create with "
|
||||
'manage_skill(action="write_file", name=..., file_path=..., '
|
||||
"file_content=...).\n\n"
|
||||
f"{COMPUTER_SKILL_AUTHORING_STANDARDS}\n\n"
|
||||
"When done, tell the user the skill name, location, and one-line summary."
|
||||
)
|
||||
|
||||
|
||||
def _apply_skills_create_prompt(messages: list[dict]) -> bool:
|
||||
for message in reversed(messages):
|
||||
if message.get("role") != "user":
|
||||
continue
|
||||
text = _plain_message_text(message.get("content"))
|
||||
match = SKILLS_CREATE_RE.match(text.strip())
|
||||
if not match:
|
||||
return False
|
||||
message["content"] = _build_skill_create_prompt(match.group(1) or "")
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# ── Task registry ───────────────────────────────────────────
|
||||
|
||||
_tasks: dict[str, asyncio.Task] = {} # message_id → asyncio.Task
|
||||
@@ -1284,6 +1382,7 @@ async def run_chat_task(
|
||||
chat_obj = await Chat.get_by_id(chat_id)
|
||||
chat_params = (chat_obj.meta or {}).get("params", {}) if chat_obj else {}
|
||||
messages, loaded_summary = await _load_message_history(chat_id, message_id)
|
||||
_apply_skills_create_prompt(messages)
|
||||
memory_message, memory_files = _memory_recall_inputs(messages, regeneration_prompt)
|
||||
system = await _load_system_prompt(
|
||||
workspace,
|
||||
@@ -1545,6 +1644,7 @@ async def run_chat_task(
|
||||
chat_params = (chat_obj.meta or {}).get("params", {}) if chat_obj else {}
|
||||
configured_model = (msg.model if msg else None) or model
|
||||
messages, loaded_summary = await _load_message_history(chat_id, message_id)
|
||||
_apply_skills_create_prompt(messages)
|
||||
memory_message, memory_files = _memory_recall_inputs(messages, regeneration_prompt)
|
||||
system = await _load_system_prompt(
|
||||
workspace,
|
||||
|
||||
Reference in new issue
Block a user