rain34572/responses-adapter-gateway
hf-space-agent
Docker-ready Hugging Face Space app:
GET /returns a simple intro HTML page.- on startup, the agent opens an outbound WebSocket connection to the Deno relay.
- on startup, optional skills sync pulls a public repo into
~/.codex/skills. - there is no public agent API route for outsiders to call directly.
Relay protocol
After websocket connect, the worker first registers persona identity:
{
"type": "agent_register",
"agentId": "hf-space-coder-v1",
"instanceId": "uuid",
"personaIds": ["coder"],
"capabilities": {
"stream": false,
"tools": false
},
"version": "2026-04-18"
}The Deno relay sends:
{
"type": "prompt",
"runId": "uuid",
"conversationId": "uuid",
"personaId": "coder",
"prompt": "your text",
"sessionId": "optional",
"continuity": {
"previousResponseId": "resp_123 or null"
},
"metadata": {}
}The agent replies on the same WebSocket:
{
"type": "response",
"runId": "uuid",
"conversationId": "uuid",
"personaId": "coder",
"responseId": "resp_456",
"reply": "agent output",
"model": "optional",
"sessionId": "optional",
"usage": {},
"raw": {}
}Environment variables
AGENT_ID(default:hf-space-agent)AGENT_INSTANCE_ID(default: auto-generated UUID at startup)AGENT_PERSONA_IDS(comma-separated, default:default)AGENT_PERSONA_ID(legacy single-persona fallback ifAGENT_PERSONA_IDSis not set)AGENT_VERSION(default:2026-04-18)AGENT_PROVIDER(default:openai_compatible)AGENT_RUNTIME(responses,codex_cli, oropencode_cli, default:codex_cli)AGENT_MODEL(default:gpt-5.3-codex)AGENT_API_KIND(responsesforresponses/codex_cli;chat_completionsforopencode_cli)AGENT_API_BASE_URL(default:https://api.openai.com/v1)AGENT_API_URL(legacy compatibility override; if set, it is converted tobase_url)AGENT_API_KEY(default: empty)AGENT_TIMEOUT_SECONDS(default:120)AGENT_PLACEHOLDER_ENABLED(default:false)AGENT_TEMPERATURE(default:0.2)AGENT_STORE(default:true; forwarded toresponses.create(store=...))CODEX_BIN(default:codex)CODEX_MODEL_PROVIDER(default:relaygw)CODEX_PROVIDER_NAME(default:Relay Gateway)CODEX_API_BASE_URL(optional override for codex_cli runtime)CODEX_API_KEY(optional override for codex_cli runtime)CODEX_MODEL(optional override for codex_cli runtime)CODEX_TIMEOUT_SECONDS(default:120)CODEX_WORKDIR(default:/tmp)OPENCODE_BIN(default:opencode)OPENCODE_HOME(default:~/.opencode-relay)OPENCODE_WORKDIR(default:/tmp)OPENCODE_PROVIDER_ID(default:relaychat, used whenAGENT_MODELhas no provider prefix)OPENCODE_PROVIDER_NAME(default:Relay Chat)DENO_AGENT_WS_URL(for example:wss://your-deno-app.example/agent)DENO_AGENT_SHARED_SECRET(must match the Deno relay)DENO_RECONNECT_SECONDS(default:5)RELAY_HINT(text shown on/)SKILLS_REPO_URL(public repo to sync skills from)SKILLS_REPO_REF(default:main)SKILLS_REPO_SUBDIR(default:skills)SKILLS_SYNC_ON_STARTUP(default:true)SKILLS_CACHE_DIR(default:/tmp/hf-space-skills-cache)AGENT_SKILLS_DIR(default:~/.agent/skills; active skills directory populated from the repo)CODEX_HOME(default:/home/appuser/.codex)DENO_KNOWLEDGE_BASE_URL(reserved for persona-knowledge skill usage)DENO_KNOWLEDGE_SHARED_SECRET(reserved for persona-knowledge skill usage)
If AGENT_API_KEY is missing and placeholder mode is enabled, the API still responds with a local placeholder message.
Runtime modes
AGENT_RUNTIME=codex_cli: invokes installedcodexCLI and continues conversations with real Codex thread ids viacodex exec resume.AGENT_RUNTIME=responses: uses official OpenAI Python SDK async client.AGENT_RUNTIME=opencode_cli: invokes installedopencodeCLI and talks to OpenAI-compatible endpoints throughchat_completions.
All runtime modes preserve relay protocol. codex_cli returns the real Codex thread id as responseId, so later turns can resume correctly. responses now retries once without previous_response_id when an OpenAI-compatible provider rejects that parameter, but that compatibility fallback does not preserve multi-turn continuity by itself. opencode_cli returns the OpenCode session id as responseId, so the relay can continue the same session after a control-plane restart.
Skills bootstrap
If SKILLS_SYNC_ON_STARTUP=true and SKILLS_REPO_URL is configured:
- startup executes a git sync into cache directory
- materializes the selected skills into
${AGENT_SKILLS_DIR} - maintains a compatibility link or copy at
${CODEX_HOME}/skills - reports sync status in
/healthzunderskills_sync
An empty enabled-skills list now means "disable all skills" instead of "load everything".
Run locally
pip install -r requirements.txt
uvicorn main:app --reload --port 7860Docker
docker build -t hf-space-agent .
docker run --rm -p 7860:7860 -e AGENT_API_KEY=your_key hf-space-agentHugging Face Space (Docker SDK)
- Create a Space with SDK set to
Docker. - Push this folder content to the Space repo.
- Configure secrets and variables:
- secret:
AGENT_API_KEY - secret:
DENO_AGENT_SHARED_SECRET - variable:
DENO_AGENT_WS_URL - variable:
AGENT_MODEL - variable:
AGENT_API_BASE_URL - variable:
AGENT_API_KIND - variable:
AGENT_STORE
