cloudflare / cloudflare/agents
think: false-positive warning "getSystemPrompt() is only used as a fallback…" fires when skills are configured without overriding getSystemPrompt
- Dominant language
- TypeScript
- Stars
- 5.6k
- Forks
- 711
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 53
Description
**Describe the bug**
Configuring Agent Skills (`getSkills()` returning a non-empty source) on a `Think` agent that does **not** override `getSystemPrompt()` still triggers the warning:
> `getSystemPrompt() is only used as a fallback when no Session context blocks are configured. getSkills() registers a skills context block, so move always-on instructions into configureSession().withContext(...) instead.`
The detection in `Think._initializeSkills()` compares function references:
```ts
if (this.getSystemPrompt !== Think.prototype.getSystemPrompt) { warn }
```
…but `Agent._autoWrapCustomMethods()` (run from the `Agent` constructor) wraps every non-base, non-private method on the subclass prototype chain with `withAgentContext(...)` and writes the new closure back onto `this.constructor.prototype` — including `getSystemPrompt` inherited from `Think.prototype`. Because `withAgentContext` always returns a fresh closure, `this.getSystemPrompt` is never reference-equal to `Think.prototype.getSystemPrompt`, so the check is a false positive whenever skills are present.
**To Reproduce**
Steps to reproduce the behavior:
1. Run the `examples/assistant` example (or any `Think` subclass that overrides `getSkills()` but not `getSystemPrompt()`).
2. Create/open a chat so `MyAssistant`'s `onStart` runs `_initializeSkills()`.
3. Observe the warning in the console.
**Expected behavior**
No warning when the user has not overridden `getSystemPrompt()` — the always-on-instructions fallback is untouched in that case. The warning should only fire when `getSystemPrompt()` is genuinely overridden (and thus silently shadowed by skills' context block).
**Screenshots**
N/A (console log).
**Version:**
`main` (current HEAD). Introduced in #1949 (`fix(think): warn when skills hide system prompt fallback`).
**Additional context**
Root cause: `_autoWrapCustomMethods()` in `packages/agents/src/index.ts` wraps subclass-visible methods (including inherited ones) with `withAgentContext` and reassigns them to `this.constructor.prototype`, so reference-identity checks against the original `Think.prototype` method can't work.
Suggested fix directions:
1. **Agents side**: when `_autoWrapCustomMethods` wraps a method, keep a reference to the original (e.g. tag `wrappedFunction` with an `__original` marker or expose a `getOriginalMethod(name)` query), and have `_initializeSkills` unwrap before comparing.
2. **Think side**: base the "was it overridden" check on the pre-wrap prototype chain rather than a reference comparison against the wrapped instance method.
Also worth adding a regression test: a `Think` subclass with non-empty `getSkills()` and **no** `getSystemPrompt()` override must not emit the warning.
Contributor guide
Research direction
Start in packages/agents/src/index.ts at Agent._autoWrapCustomMethods(), then trace Think._initializeSkills() and its getSystemPrompt reference check. Reproduce the warning with examples/assistant or a Think subclass that returns non-empty skills without overriding getSystemPrompt(). Done means the warning is absent in that case and remains for a genuine override, with a regression test covering the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100