Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ jobs:
- uses: astral-sh/setup-uv@v5
- run: uv python install 3.10
- run: uv sync --extra all
- run: uv run ruff check .
- run: uv run ruff format --check .
- run: uvx ruff@0.12.2 check .
- run: uvx ruff@0.12.2 format --check .
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ Thumbs.db
# Environment
.env
*.env.local

# uv
uv.lock
2 changes: 1 addition & 1 deletion evolve_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"""

from .core.config import EvolveServerConfig
from .core.constants import DecisionAction, FailureType, FAILURE_LABELS, NO_SKILL_KEY
from .core.constants import FAILURE_LABELS, NO_SKILL_KEY, DecisionAction, FailureType
from .core.llm_client import AsyncLLMClient
from .core.skill_registry import SkillIDRegistry
from .engines.agent import AgentEvolveServer
Expand Down
57 changes: 32 additions & 25 deletions evolve_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,12 @@ def build_parser() -> argparse.ArgumentParser:
help="Evolution engine: fixed workflow or OpenClaw agent.",
)
parser.add_argument("--once", action="store_true", help="Run once and exit")
parser.add_argument("--mock", action="store_true",
help="Use local mock/ directory instead of remote object storage")
parser.add_argument("--mock-root", type=str, default=None,
help="Custom root directory for mock mode")
parser.add_argument("--port", type=int, default=None,
help="HTTP trigger port (enables HTTP server)")
parser.add_argument("--interval", type=int, default=None,
help="Periodic interval in seconds")
parser.add_argument(
"--mock", action="store_true", help="Use local mock/ directory instead of remote object storage"
)
parser.add_argument("--mock-root", type=str, default=None, help="Custom root directory for mock mode")
parser.add_argument("--port", type=int, default=None, help="HTTP trigger port (enables HTTP server)")
parser.add_argument("--interval", type=int, default=None, help="Periodic interval in seconds")
parser.add_argument(
"--publish-mode",
choices=["direct", "validated"],
Expand Down Expand Up @@ -179,23 +177,29 @@ def build_parser() -> argparse.ArgumentParser:
default=None,
help="Use a local directory as the evolve backend root",
)
parser.add_argument("--use-skillclaw-config", action="store_true",
help="Load shared storage and LLM settings from skillclaw's config store")
parser.add_argument("--openclaw-bin", type=str, default=None,
help="Path to openclaw executable for --engine agent")
parser.add_argument("--openclaw-home", type=str, default=None,
help="OPENCLAW_HOME directory for --engine agent")
parser.add_argument(
"--use-skillclaw-config",
action="store_true",
help="Load shared storage and LLM settings from skillclaw's config store",
)
parser.add_argument("--openclaw-bin", type=str, default=None, help="Path to openclaw executable for --engine agent")
parser.add_argument("--openclaw-home", type=str, default=None, help="OPENCLAW_HOME directory for --engine agent")
fresh_group = parser.add_mutually_exclusive_group()
fresh_group.add_argument("--fresh", dest="fresh", action="store_true", default=None,
help="Wipe agent state each cycle (agent engine only)")
fresh_group.add_argument("--no-fresh", dest="fresh", action="store_false",
help="Preserve agent state across cycles (agent engine only)")
parser.add_argument("--agent-timeout", type=int, default=None,
help="Agent execution timeout in seconds")
parser.add_argument("--workspace-root", type=str, default=None,
help="Workspace directory for agent file operations")
parser.add_argument("--agents-md", type=str, default=None,
help="Custom EVOLVE_AGENTS.md path for agent engine")
fresh_group.add_argument(
"--fresh",
dest="fresh",
action="store_true",
default=None,
help="Wipe agent state each cycle (agent engine only)",
)
fresh_group.add_argument(
"--no-fresh", dest="fresh", action="store_false", help="Preserve agent state across cycles (agent engine only)"
)
parser.add_argument("--agent-timeout", type=int, default=None, help="Agent execution timeout in seconds")
parser.add_argument(
"--workspace-root", type=str, default=None, help="Workspace directory for agent file operations"
)
parser.add_argument("--agents-md", type=str, default=None, help="Custom EVOLVE_AGENTS.md path for agent engine")
parser.add_argument("--verbose", "-v", action="store_true")
return parser

Expand Down Expand Up @@ -259,7 +263,10 @@ def main() -> None:

async def _run_with_http():
uv_config = uvicorn.Config(
app, host="0.0.0.0", port=config.http_port, log_level="info",
app,
host="0.0.0.0",
port=config.http_port,
log_level="info",
)
uv_server = uvicorn.Server(uv_config)
await asyncio.gather(server.run_periodic(), uv_server.serve())
Expand Down
27 changes: 14 additions & 13 deletions evolve_server/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ def _infer_storage_backend(endpoint: str, bucket: str, local_root: str) -> str:
return backend
if local_root:
return "local"
if any(os.environ.get(name) for name in ("EVOLVE_OSS_ENDPOINT", "EVOLVE_OSS_BUCKET", "EVOLVE_OSS_KEY_ID", "EVOLVE_OSS_KEY_SECRET")):
if any(
os.environ.get(name)
for name in (
"EVOLVE_OSS_ENDPOINT",
"EVOLVE_OSS_BUCKET",
"EVOLVE_OSS_KEY_ID",
"EVOLVE_OSS_KEY_SECRET",
)
):
return "oss"
if endpoint or bucket:
return "s3"
Expand Down Expand Up @@ -232,19 +240,11 @@ def from_skillclaw_config(cls, config) -> "EvolveServerConfig":
engine = _first_env("EVOLVE_ENGINE", default="workflow").strip().lower() or "workflow"
storage_backend = str(getattr(config, "sharing_backend", "") or "").strip().lower()
storage_endpoint = str(
getattr(config, "sharing_endpoint", "")
or getattr(config, "sharing_oss_endpoint", "")
or ""
)
storage_bucket = str(
getattr(config, "sharing_bucket", "")
or getattr(config, "sharing_oss_bucket", "")
or ""
getattr(config, "sharing_endpoint", "") or getattr(config, "sharing_oss_endpoint", "") or ""
)
storage_bucket = str(getattr(config, "sharing_bucket", "") or getattr(config, "sharing_oss_bucket", "") or "")
storage_access_key_id = str(
getattr(config, "sharing_access_key_id", "")
or getattr(config, "sharing_oss_access_key_id", "")
or ""
getattr(config, "sharing_access_key_id", "") or getattr(config, "sharing_oss_access_key_id", "") or ""
)
storage_secret_access_key = str(
getattr(config, "sharing_secret_access_key", "")
Expand Down Expand Up @@ -281,7 +281,8 @@ def from_skillclaw_config(cls, config) -> "EvolveServerConfig":

return cls(
engine=engine,
storage_backend=storage_backend or ("local" if local_root else "s3" if (storage_bucket or storage_endpoint) else "oss"),
storage_backend=storage_backend
or ("local" if local_root else "s3" if (storage_bucket or storage_endpoint) else "oss"),
storage_endpoint=storage_endpoint,
storage_bucket=storage_bucket,
storage_access_key_id=storage_access_key_id,
Expand Down
2 changes: 2 additions & 0 deletions evolve_server/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class FailureType(IntEnum):
"""Five-way failure taxonomy for a bad turn."""

SKILL_CONTENT_STALE = 1
SKILL_MISSELECT = 2
SKILL_GAP = 3
Expand All @@ -33,6 +34,7 @@ class FailureType(IntEnum):

class DecisionAction:
"""Allowed evolution-decision action identifiers."""

CREATE = "create_skill"
IMPROVE = "improve_skill"
OPTIMIZE_DESC = "optimize_description"
Expand Down
9 changes: 6 additions & 3 deletions evolve_server/core/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(
max_tokens: int = 100000,
temperature: float = 0.4,
) -> None:
from openai import OpenAI
import httpx
from openai import OpenAI

self._client = OpenAI(
api_key=api_key or os.environ.get("OPENAI_API_KEY", ""),
Expand All @@ -58,7 +58,8 @@ async def chat(self, messages: list[dict[str, str]], **kwargs: Any) -> str:
for attempt in range(max_retries):
try:
resp = await asyncio.to_thread(
self._client.chat.completions.create, **merged,
self._client.chat.completions.create,
**merged,
)
return resp.choices[0].message.content or ""
except Exception as exc:
Expand All @@ -71,13 +72,15 @@ async def chat(self, messages: list[dict[str, str]], **kwargs: Any) -> str:
return await self._chat_via_stream(merged)
if attempt < max_retries - 1:
import random
wait = min(2 ** attempt + random.uniform(0, 1), 30)

wait = min(2**attempt + random.uniform(0, 1), 30)
await asyncio.sleep(wait)
continue
raise

async def _chat_via_stream(self, body: dict[str, Any]) -> str:
import json

import httpx

headers: dict[str, str] = {}
Expand Down
14 changes: 8 additions & 6 deletions evolve_server/core/skill_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ def record_update(
entry["version"] = new_version
entry["content_sha"] = content_sha
history: list = entry.setdefault("history", [])
history.append({
"version": new_version,
"content_sha": content_sha,
"timestamp": datetime.now(timezone.utc).isoformat(),
"action": action,
})
history.append(
{
"version": new_version,
"content_sha": content_sha,
"timestamp": datetime.now(timezone.utc).isoformat(),
"action": action,
}
)
if len(history) > 20:
entry["history"] = history[-20:]

Expand Down
5 changes: 3 additions & 2 deletions evolve_server/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import re
from typing import Any, Optional


# ------------------------------------------------------------------ #
# LLM output parsing #
# ------------------------------------------------------------------ #


def parse_single_skill(text: str) -> Optional[dict]:
"""Extract a single skill JSON object from LLM output."""
clean = re.sub(r"```(?:json)?\s*", "", text.strip()).strip().rstrip("`")
Expand Down Expand Up @@ -99,14 +99,15 @@ def compact_tool_observations(
# SKILL.md rendering #
# ------------------------------------------------------------------ #


def build_skill_md(skill: dict) -> str:
"""Render a skill dict into SKILL.md content (with YAML frontmatter)."""
name = skill.get("name", "unknown")
description = skill.get("description", "")
category = skill.get("category", "general")
content = skill.get("content", "")

needs_quoting = any(c in description for c in ':{}[],"\'#&*!|>%@`\n')
needs_quoting = any(c in description for c in ":{}[],\"'#&*!|>%@`\n")
if needs_quoting:
escaped = description.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
desc_line = f'description: "{escaped}"'
Expand Down
Loading
Loading