4.0 KiB
LangGraph Implementation Idea
Goal
Add a session-based agent gateway in front of Ollama so the Minecraft AI system can:
- keep per-player/session memory,
- run multi-step tool calls (MCP/web search),
- return a final
message + commandspayload to the existing plugin.
This is a future enhancement. Current system is working and remains the source of truth for command execution safety.
Why This Exists
Current mc_aigod.py calls Ollama directly. That is effectively stateless unless full history is re-sent every call.
A LangGraph sidecar can provide:
- persistent sessions/threads,
- tool loop orchestration,
- model routing,
- better observability of intermediate reasoning steps.
Proposed Architecture
Minecraft chat -> mc_aigod.py -> LangGraph Gateway API -> Ollama
| \
| -> MCP tools (web search/wiki/etc)
-> Session store (SQLite/Redis)
mc_aigod.py remains responsible for:
- trigger parsing (
pray,bible,sudo), - RCON command execution,
- whitelist/validation/fixups,
- hard safety rules (e.g. first-login kill limits).
LangGraph gateway is responsible for:
- session state,
- tool calls,
- composing final JSON output.
API Contract Sketch
Start session
POST /v1/session/start
Request:
{
"player": "slingshooter08",
"mode": "god"
}
Response:
{
"session_id": "sess_abc123"
}
Send message
POST /v1/session/{session_id}/message
Request:
{
"role": "user",
"text": "pray I need wood for shelter",
"context": {
"server_state": {},
"player_state": {},
"recent_events": []
},
"allow_tools": true,
"max_tool_steps": 4
}
Response:
{
"message": "Divine response text",
"commands": [
"give slingshooter08 minecraft:oak_log 64"
],
"tool_trace": [
{
"tool": "web.search",
"input": "minecraft oak log item id",
"ok": true
}
]
}
End session (optional)
POST /v1/session/{session_id}/close
LangGraph Flow (Draft)
- Load session state by
session_id - Add user message + context
- Call command model
- If tool requested:
- execute MCP tool
- append tool result
- loop until final commands or step limit reached
- Call message model with chosen commands
- Return final
{message, commands} - Persist updated session state
Tooling Plan
Primary tools to add first:
web.search(general search)minecraft.wiki_lookup(targeted page fetch/search)
Potential later tools:
- local documentation lookup,
- server analytics lookup,
- schematic index lookup.
Modes to Support
god(prayer flow, tool-enabled)sudo(translator flow, likely tool-disabled or very limited)god_system(intervention/first-login internal events)
Safety Model (Keep in mc_aigod.py)
Even after LangGraph is added, keep hard enforcement in plugin runtime:
- whitelist command families,
- syntax repair + normalization,
- max commands cap,
- per-flow constraints (e.g. first-login benevolence restrictions),
- unauthorized sudo user rejection.
This ensures model/tool errors cannot directly bypass execution safeguards.
MVP Steps (Later)
- Build FastAPI LangGraph gateway with in-memory sessions
- Add
/session/start+/session/{id}/message - Mirror current two-call behavior (no tools yet)
- Switch
mc_aigod.pyto gateway endpoint - Add one MCP search tool and bounded tool loop
- Add persistence (SQLite/Redis)
- Add structured logs + tool traces
Open Questions
- Session lifetime policy (per player, per login, time-based expiry?)
- Whether
sudoshould ever be tool-enabled - How much tool trace to expose in-game vs log-only
- Which MCP stack to standardize on for web search
Notes
This document is a planning scratchpad for future implementation. It is intentionally practical and API-first so a coder bot can pick it up and implement directly.