Agent Movement API
Documentation for the movement completion tracking API added to HyperscapeService.Overview
The HyperscapeService now provides movement completion tracking, allowing actions to wait for movement to finish before proceeding. This is critical for multi-step actions like banking (walk to bank → deposit items).API Reference
waitForMovementComplete(timeoutMs?: number): Promise<void>
Wait for the current movement to complete. Resolves immediately if not moving.
Parameters:
timeoutMs(optional): Maximum time to wait in milliseconds (default: 15000)
isMoving: boolean
Read-only property indicating if the character is currently moving.
Example:
Implementation Details
Movement State Tracking
The service tracks movement state using two internal properties:_isMoving: Boolean flag set whenexecuteMove()is called_movementResolve: Promise resolver called whentileMovementEndpacket received
Packet Flow
-
Movement Start:
-
Server Processing:
- Server validates movement
- Sends
tileMovementStartpacket - Sends
entityTileUpdatepackets during movement - Sends
tileMovementEndpacket when complete
-
Movement Complete:
Timeout Handling
If movement doesn’t complete within the timeout period:- Promise resolves anyway (doesn’t reject)
_isMovingflag is cleared- Prevents actions from hanging indefinitely
Use Cases
Banking Actions
Banking requires the character to be at the bank before depositing:Resource Gathering
Approach a resource before gathering:Combat Positioning
Move into attack range before attacking:Action Lock Integration
The movement API integrates with the action lock system to prevent LLM ticks during movement:Fast-Tick Mode
After movement completes, the autonomous behavior manager enters “fast-tick mode” for 2 seconds:- Normal tick interval: 10 seconds
- Fast-tick interval: 2 seconds
- Triggered by: Movement completion, goal changes
Migration Guide
Before (Broken)
After (Fixed)
Related Changes
This API was added as part of the agent stability improvements (PR #945):- Action locks: Skip LLM ticks during movement
- Fast-tick mode: 2s interval after movement/goal changes
- Short-circuit LLM: Obvious decisions bypass LLM
- Banking protocol: Proper sequence with movement awaiting
See Also
- packages/plugin-hyperscape/src/services/HyperscapeService.ts - Implementation
- packages/plugin-hyperscape/src/actions/banking.ts - Banking action example
- docs/agent-stability-improvements.md - Agent stability fixes