Agent Skillssandgardenhq/sgai › using-sgai

using-sgai

GitHub

指导 AI Agent 通过 HTTP API 或 MCP 驱动 sgai 软件工厂系统,涵盖工作区、会话管理及人机交互的探测轮询执行循环。

docs/sgai-skills/using-sgai/SKILL.md sandgardenhq/sgai

触发场景

需要自动化管理 AI 软件工厂工作区 需要通过 MCP 协议集成 sgai 服务 需要处理 AI Agent 的人机交互流程

安装

npx skills add sandgardenhq/sgai --skill using-sgai -g -y
更多选项

非标准路径

npx skills add https://github.com/sandgardenhq/sgai/tree/main/docs/sgai-skills/using-sgai -g -y

不安装直接使用

npx skills use sandgardenhq/sgai@using-sgai

指定 Agent (Claude Code)

npx skills add sandgardenhq/sgai --skill using-sgai -a claude-code -g -y

安装 repo 全部 skill

npx skills add sandgardenhq/sgai --all -g -y

预览 repo 内 skill

npx skills add sandgardenhq/sgai --list

SKILL.md

Frontmatter
{
    "name": "using-sgai",
    "description": "Drive sgai (Software Garden AI) from any MCP-capable harness or AI agent. Covers the cyclical probe\/poll\/act workflow for managing AI software factory workspaces, sessions, and human interaction. Use this as the entrypoint when orchestrating sgai from Claude Code, Codex, or any AI harness.",
    "compatibility": "Requires a running sgai server (sgai serve). Works with any HTTP client or MCP-capable harness."
}

Using sgai from an AI Harness

sgai is a software factory system that runs AI agents in workspaces. This skill teaches you to drive it via the HTTP API or MCP tools.

Quick Start: Base URL

All examples assume BASE_URL=http://127.0.0.1:PORT where PORT is shown in the server startup log:

sgai serve listening on http://127.0.0.1:PORT

The MCP endpoint is at /mcp/external on the same server (e.g. http://127.0.0.1:PORT/mcp/external).

The Cyclical Probe/Poll/Act Loop

The core pattern for driving sgai is a continuous loop:

LOOP:
  1. PROBE  → GET /api/v1/state          # Discover all workspaces + status
  2. CHECK  → pendingQuestion != null?   # Does any workspace need human input?
  3. ACT    → based on workspace status  # Start, respond, or wait
  4. WAIT   → poll again after delay     # Repeat

Step 1: Probe — Get Factory State

curl -s $BASE_URL/api/v1/state

Response shape:

{
  "workspaces": [
    {
      "name": "my-project",
      "running": false,
      "needsInput": false,
      "inProgress": false,
      "status": "agent-done",
      "task": "Planning implementation",
      "pendingQuestion": null
    }
  ]
}

Key fields to check per workspace:

  • running — is a session active?
  • needsInput — does the agent need a human response?
  • pendingQuestion — non-null when human input is required
  • status — current workflow status string
  • inProgress — is work actively happening?

Step 2: Check for Pending Questions

When workspace.pendingQuestion != null, the agent is blocked waiting for human input.

{
  "pendingQuestion": {
    "questionId": "abc123def456",
    "type": "free-text",
    "agentName": "coordinator",
    "message": "Which approach should we take?",
    "questions": []
  }
}

Question types:

  • "free-text" — respond with a text answer
  • "multi-choice" — select from provided choices
  • "work-gate" — approve to proceed (select approval text)

Step 3: Act Based on Status

Workspace State Action
needsInput: true Call respond endpoint with answer
running: false and has goal Start session
running: true Monitor
Session complete Check results, start next task

Step 4: Respond to Questions

# Free-text response
curl -s -X POST $BASE_URL/api/v1/workspaces/{name}/respond \
  -H "Content-Type: application/json" \
  -d '{"questionId": "abc123def456", "answer": "Use the microservice approach"}'

# Multi-choice response
curl -s -X POST $BASE_URL/api/v1/workspaces/{name}/respond \
  -H "Content-Type: application/json" \
  -d '{"questionId": "abc123def456", "selectedChoices": ["Option A"]}'

Sub-skills

For detailed documentation on specific operations:

MCP Interface

If using the MCP interface instead of HTTP, all tools are available at /mcp/external:

# List all 38 tools
npx mcporter list --http-url http://HOST:PORT/mcp/external --allow-http

Key MCP tools mirror the HTTP API:

  • list_workspaces → GET /api/v1/state
  • start_session → POST /api/v1/workspaces/{name}/start
  • respond_to_question → POST /api/v1/workspaces/{name}/respond
  • wait_for_question → polls + elicitation (MCP only)

Real-Time Updates via SSE

Subscribe to state changes instead of polling:

curl -s -N $BASE_URL/api/v1/signal
# Emits: event: reload\ndata: {}\n\n

When you receive a reload event, re-fetch /api/v1/state.

Common Workflow: Start a Project End-to-End

# 1. Create workspace
curl -X POST $BASE_URL/api/v1/workspaces \
  -d '{"name": "my-project"}'

# 2. Write a GOAL.md
curl -X PUT $BASE_URL/api/v1/workspaces/my-project/goal \
  -d '{"content": "# My Goal\n- [ ] Build the feature"}'

# 3. Start session in auto (self-drive) mode
curl -X POST $BASE_URL/api/v1/workspaces/my-project/start \
  -d '{"auto": true}'

# 4. Poll for completion
while true; do
  STATE=$(curl -s $BASE_URL/api/v1/state)
  NEEDS_INPUT=$(echo $STATE | jq '.workspaces[0].needsInput')
  if [ "$NEEDS_INPUT" = "true" ]; then
    # Handle question...
  fi
  sleep 5
done

版本历史

  • 9efbb7b 当前 2026-07-25 08:54

同 Skill 集合

docs/sgai-skills/adhoc/SKILL.md
docs/sgai-skills/compose/SKILL.md
docs/sgai-skills/human-interaction/SKILL.md
docs/sgai-skills/knowledge/SKILL.md
docs/sgai-skills/monitoring/SKILL.md
docs/sgai-skills/session-control/SKILL.md
docs/sgai-skills/workspace-management/SKILL.md

元信息

文件数
0
版本
9efbb7b
Hash
80f86bc9
收录时间
2026-07-25 08:54

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-28 22:58
浙ICP备14020137号-1 $访客地图$