simulatecraft.brains.llm¶
simulatecraft.brains.llm
¶
LLMBrain: pydantic-ai-driven reasoning behind the standard Brain interface.
This is the ONLY module in the package that imports pydantic_ai. Its API
moves fast, so every pydantic-ai-specific call lives here; pin the exact
version in pyproject.toml and upgrade in this single file.
Model string formats accepted by LLMBrain / resolve_model()¶
"groq:openai/gpt-oss-120b"← Groq free tier, default ⚡"groq:openai/gpt-oss-20b"← Groq free tier, faster/smaller"groq:qwen/qwen3.6-27b"← Groq free tier, strong reasoning"openrouter:meta-llama/llama-3.1-8b-instruct:free"← OpenRouter free tier"openrouter:anthropic/claude-sonnet-4.6"← OpenRouter paid"anthropic:claude-sonnet-4-5"← direct Anthropic key"openai:gpt-4o-mini"← direct OpenAI key"openai-compatible:oc/mimo-v2.5-free"← any OpenAI-compatible gateway"oc/mimo-v2.5-free"← same, when OPENAI_BASE_URL is set"google-gla:gemini-2.0-flash"← direct Google key"test"← offline TestModel, no key needed
Auto-selection order (resolve_model): GROQ_API_KEY → OPENROUTER_API_KEY → "test"
OpenAI-compatible gateways (9Router, LiteLLM, vLLM, …)¶
export OPENAI_BASE_URL=http://localhost:20128/v1
export OPENAI_API_KEY=<dashboard-key>
export SIMULATECRAFT_MODEL=oc/mimo-v2.5-free
BrainDeps
¶
Bases: BaseModel
Dependency-injected context handed to the pydantic-ai agent each run.
LLMBrain
¶
LLMBrain(action_types: list[type[Action]], *, persona: str, model: str | Any = 'test', config: LLMBrainConfig | None = None, instructions: str | None = None, memory: MemoryStream | None = None, retriever: Retriever | None = None, planner: Planner | None = None, skills: SkillRegistry | None = None, summarizer: Any = None)
Bases: Brain[Observation]
Decides via an LLM with validated structured output (no manual parsing).
- Available actions are exposed through pydantic-ai's
output_typeas a discriminated union of your Action subclasses, so the model's choice arrives as an already-validated Action instance. - Schema failures are handled by pydantic-ai's native retry mechanism.
- Provider switching is just the
modelstring ("anthropic:...", "openai:...", "google-gla:...", "google-gla:gemini-...").
Source code in src/simulatecraft/brains/llm.py
resolve_model
¶
Read the model string from the environment, auto-selecting a free provider.
Priority¶
SIMULATECRAFT_MODELenv var — any format accepted: openrouter:meta-llama/llama-3.1-8b-instruct:free groq:openai/gpt-oss-120b anthropic:claude-sonnet-4-5 openai:gpt-4o-mini testGROQ_API_KEYpresent →groq:openai/gpt-oss-120b(Groq is free-tier, very fast — best default for agent tick loops)OPENROUTER_API_KEYpresent →openrouter:meta-llama/llama-3.1-8b-instruct:free- No keys at all →
"test"(offline TestModel, zero network calls)