Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:4thfever Cultivation world simulator LLM Provider Connectivity

From Leeroopedia
Knowledge Sources
Domains LLM, Backend
Last Updated 2026-10-22 16:00 GMT

Overview

OpenAI-compatible or Anthropic LLM API endpoint with API key, required for NPC AI decisions, story generation, and world lore rewriting.

Description

The Cultivation World Simulator relies on a remote LLM provider for all narrative and AI decision-making. The provider must expose either an OpenAI-compatible chat completions API or the Anthropic Messages API. Configuration is stored in `settings.json` / `secrets.json` under the user data directory, with optional environment-variable seeding for Docker/desktop deployments. The system supports two modes: NORMAL (full-quality model) and FAST (cheaper/faster model), with per-task mode routing via `config.yml`.

Usage

Use this environment whenever the simulation needs to make LLM calls: NPC action decisions, backstory generation, story telling, nickname generation, sect thinking, world lore rewriting, and roleplay conversations. In test mode (`RunConfig.test_mode=True`), LLM calls are replaced by deterministic fallbacks and no provider connectivity is needed.

System Requirements

Category Requirement Notes
Network HTTP(S) access to LLM API endpoint Latency-sensitive; async with semaphore-limited concurrency
API Key Valid LLM provider API key Stored in `secrets.json`, never returned to frontend
API Format "openai" or "anthropic" Configured per LLM profile

Dependencies

Python Packages

Configuration Files

  • `settings.json` — LLM profile (base_url, model_name, fast_model_name, mode, api_format, max_concurrent_requests)
  • `secrets.json` — API keys (primary and optional fast-mode separate key)
  • `static/config.yml` — `llm.default_modes` section for per-task mode routing

Credentials

The following must be configured in `settings.json` / `secrets.json` or via environment variables:

  • `CWS_DEFAULT_LLM_BASE_URL`: LLM API base URL (e.g., `https://api.openai.com/v1`)
  • `CWS_DEFAULT_LLM_MODEL`: Primary model name
  • `CWS_DEFAULT_LLM_FAST_MODEL`: Fast-mode model name
  • `CWS_DEFAULT_LLM_API_KEY`: API key (stored in secrets.json, never sent to frontend)
  • `CWS_DEFAULT_LLM_API_FORMAT`: "openai" or "anthropic" (default: "openai")
  • `CWS_DEFAULT_LLM_MODE`: "default", "normal", or "fast" (default: "default")
  • `CWS_DEFAULT_LLM_MAX_CONCURRENT_REQUESTS`: Integer 1-50 (default: 10)

Note: API keys are never returned to the frontend. The settings API strips secrets before sending to the web client.

Quick Install

# No additional pip install needed — LLM calls use stdlib urllib
# Configure via environment variables for Docker/desktop:
export CWS_DEFAULT_LLM_BASE_URL="https://api.openai.com/v1"
export CWS_DEFAULT_LLM_MODEL="gpt-4o"
export CWS_DEFAULT_LLM_FAST_MODEL="gpt-4o-mini"
export CWS_DEFAULT_LLM_API_KEY="sk-..."
export CWS_DEFAULT_LLM_API_FORMAT="openai"

Code Evidence

LLM configuration loading from `src/config/settings_service.py:87-112`:

base_url = os.environ.get("CWS_DEFAULT_LLM_BASE_URL", "").strip()
model_name = os.environ.get("CWS_DEFAULT_LLM_MODEL", "").strip()
fast_model_name = os.environ.get("CWS_DEFAULT_LLM_FAST_MODEL", "").strip()
api_key = os.environ.get("CWS_DEFAULT_LLM_API_KEY", "").strip()

if not (base_url and model_name and fast_model_name and api_key):
    return None

Test mode short-circuit from `src/utils/llm/client.py:491-492`:

if is_test_mode_enabled():
    return resolve_test_mode_task(task_name, infos)

API format selection from `src/utils/llm/config.py:38-39`:

api_format = getattr(profile, "api_format", "openai") or "openai"

Common Errors

Error Message Cause Solution
`CONFIG_REQUIRED` failure kind No LLM API key or base_url configured Set `CWS_DEFAULT_LLM_*` env vars or configure in settings UI
`RATE_LIMITED` failure kind LLM provider returned 429 or quota error Check provider billing/quota; reduce `max_concurrent_requests`
`TestModeUnsupportedLLMTask` New LLM task not registered in test mode fallbacks Add task to `resolve_test_mode_task()` in `test_mode_fallbacks.py`
`ParseError` LLM returned non-JSON or malformed response Check prompt template; LLM may need better instructions

Compatibility Notes

  • OpenAI-compatible APIs: Supported as default (`api_format="openai"`). Works with OpenAI, Azure OpenAI, vLLM, LM Studio, etc.
  • Anthropic API: Supported via `api_format="anthropic"`. Uses Anthropic Messages API format.
  • Test Mode: When `RunConfig.test_mode=True`, all LLM calls are replaced by deterministic fallbacks. Unknown tasks raise `TestModeUnsupportedLLMTask` (fail-closed).
  • Offline/No key: Simulation can start without LLM config, but NPC decisions and story generation will fail at runtime.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment