DiscordPHP-NHA Documentation

AgentBrain
in package

FinalYes

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
link
https://nha.recluse.lol/AGENTS.md
https://nha.recluse.lol/docs#/agent/submit_intent_intent_post
since
3.0.0

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

$ollama  : OllamaClient

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

Methods

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: array, reason: string}|null>

null 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: array, reason: string}|null

summarize()

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.

Return values
string
On this page

Search results