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

Implementation:4thfever Cultivation world simulator LLMAI decide

From Leeroopedia
Knowledge Sources
Domains AI_Agents, LLM_Applications
Last Updated 2026-10-22 14:00 GMT

Overview

Concrete tool for generating NPC decisions via LLM, converting assembled world context into structured action chains with thinking and objectives, provided by the Cultivation World Simulator AI system.

Description

The LLMAI class implements the `AI` abstract base class. Its `_decide` method is the core decision engine: for each eligible avatar, it assembles context (avatar info, world info, action catalog, world lore), calls the LLM via `call_llm_with_task_name("action_decision", ...)`, parses the JSON response into action pairs, extracts thinking and short-term objective, and updates the avatar's emotion.

The public `decide` method wraps `_decide` and appends a `NULL_EVENT` as the fourth tuple element (start events are deferred to the commit phase).

All avatar decisions are dispatched concurrently via `asyncio.gather`.

Usage

Import and use this class when:

  • AI decision phase: `phase_decide_actions` calls `llm_ai.decide(world, avatars_to_decide)`
  • Testing: mock or replace with a rule-based AI in test mode (handled by `call_llm_with_task_name`'s test-mode fallback)

Code Reference

Source Location

Signature

class AI(ABC):
    @abstractmethod
    async def _decide(self, world: World, avatars_to_decide: list[Avatar]) -> dict[Avatar, tuple]:
        pass

    async def decide(self, world: World, avatars_to_decide: list[Avatar]) -> dict[Avatar, tuple[ACTION_NAME_PARAMS_PAIRS, str, str, Event]]:
        """Decide actions for all eligible avatars, returning (action_pairs, thinking, objective, event)."""

class LLMAI(AI):
    async def _decide(self, world: World, avatars_to_decide: list[Avatar]) -> dict[Avatar, tuple[ACTION_NAME_PARAMS_PAIRS, str, str]]:
        """LLM-driven decision: concurrent per-avatar LLM calls, JSON response parsing."""

llm_ai = LLMAI()  # module-level singleton

Import

from src.classes.ai import LLMAI, llm_ai

I/O Contract

Inputs

Name Type Required Description
world World Yes World instance for info assembly
avatars_to_decide list[Avatar] Yes Pre-filtered avatars needing decisions

Outputs

Name Type Description
return dict[Avatar, tuple[ACTION_NAME_PARAMS_PAIRS, str, str, Event]] Per-avatar: (action pairs, thinking, short-term objective, NULL_EVENT)

Usage Examples

Decide Actions for All Eligible Avatars

from src.classes.ai import llm_ai

# Filter avatars: only those with no current action and no plans
avatars_to_decide = [a for a in living_avatars if a.current_action is None and not a.has_plans()]

results = await llm_ai.decide(world, avatars_to_decide)
for avatar, (pairs, thinking, objective, _event) in results.items():
    avatar.load_decide_result_chain(pairs, thinking, objective)
    print(f"{avatar.name}: {len(pairs)} actions planned")

Related Pages

Implements Principle

Required Environments

Uses Heuristics

Page Connections

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