AgentBrain
in package
Turns one {@see AgentObservation} into a single game action by asking an LLM (via {@see OllamaClient}) and parsing a strict JSON reply.
This is deliberately a consumer-application concern: it assembles the prompt (strategy in Playbook, the situation digest in PromptBuilder) and validates the model's choice, but it does NOT submit intents or hold game transport — AutoPlayer wires it to NHA.
The deterministic fallback the model is anchored against — and that AutoPlayer drops to when a pick is refused — lives in Ladder.
Tags
Table of Contents
Constants
- VERBS : array<string, string> = \NHA\Brain\Playbook::VERBS
- The verbs the brain may pick. Kept as an alias so existing `AgentBrain::VERBS` callers keep working; the catalogue lives in {@see Playbook::VERBS} alongside the strategy that references it.
Properties
Methods
- __construct() : mixed
-
decide()
: PromiseInterface<string|int, array{verb: string, args: array
, reason: string}|null> - Asks the model for the next action.
-
parseDecision()
: array{verb: string, args: array
, reason: string}|null - Parses a model reply into a validated decision, or `null`.
- summarize() : string
- The model's user turn — the situation digest. Delegates to {@see PromptBuilder::build()}; kept here so `AgentBrain::summarize()` callers (and tests) are unaffected by the split.
Constants
VERBS
The verbs the brain may pick. Kept as an alias so existing `AgentBrain::VERBS` callers keep working; the catalogue lives in {@see Playbook::VERBS} alongside the strategy that references it.
public
array<string, string>
VERBS
= \NHA\Brain\Playbook::VERBS
Properties
$ollama read-only
private
OllamaClient
$ollama
Methods
__construct()
public
__construct(OllamaClient $ollama) : mixed
Parameters
- $ollama : OllamaClient
-
The LLM client prompted for each decision.
decide()
Asks the model for the next action.
public
decide(AgentObservation $observation[, array{verb: string, args: array, reason: string, tick: ?int}|null $lastDecision = null ][, string $stance = 'homestead' ]) : PromiseInterface<string|int, array{verb: string, args: array, reason: string}|null>
Parameters
- $observation : AgentObservation
-
This tick's perception.
- $lastDecision : array{verb: string, args: array, reason: string, tick: ?int}|null = null
-
The previous turn's decision, if known — shown to the model so it does not loop on a failed verb.
- $stance : string = 'homestead'
Return values
PromiseInterface<string|int, array{verb: string, args: arraynull when the model chose wait or returned nothing usable.
parseDecision()
Parses a model reply into a validated decision, or `null`.
public
static parseDecision(string $content) : array{verb: string, args: array, reason: string}|null
Tolerates ```json fences and leading prose; requires a known verb.
Parameters
- $content : string
Return values
array{verb: string, args: arraysummarize()
The model's user turn — the situation digest. Delegates to {@see PromptBuilder::build()}; kept here so `AgentBrain::summarize()` callers (and tests) are unaffected by the split.
public
summarize(AgentObservation $observation[, array{verb: string, args: array, reason: string, tick: ?int}|null $lastDecision = null ]) : string
Parameters
- $observation : AgentObservation
- $lastDecision : array{verb: string, args: array, reason: string, tick: ?int}|null = null
-
The previous turn, if known.