-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Describe the bug
When initializing AgentRuntime
, the following code in runtime.ts
:
tsthis.agent = await this.adapter.getAgent(this.character.id);
throws an unhandled exception if:
- the agents table does not exist (e.g. migrations incomplete), or
- character.id is missing/undefined.
This prevents runtime startup and crashes the process.
To Reproduce
Run AgentRuntime with a new Postgres database where the agents table has not been created.
Or, start with a character config missing an id field.
Observe the runtime crash with getAgent error.
Expected behavior
If getAgent() fails due to a missing record, the runtime should gracefully create the agent with createAgent().
If character.id is missing, a clear error should be logged, not an unhandled exception.
Screenshots
N/A but here are the logs
Database operation failed (attempt 1/3): Failed query: select "id", "name", "bio" from "agents"
2025-09-25 14:53:12 params: , nextRetryIn: 1.9s
2025-09-25 14:53:14 Warn Database operation failed (attempt 2/3): Failed query: select "id", "name", "bio" from "agents"
2025-09-25 14:53:14 params: , nextRetryIn: 2.8s
2025-09-25 14:53:17 Error Max retry attempts reached: Failed query: select "id", "name", "bio" from "agents"
2025-09-25 14:53:17 params: , totalAttempts: 3
Additional context
Proposed fix is to wrap getAgent() in a try/catch and fall back to createAgent() where possible.