open-multi-agent/tests
JackChen a86a448fa0
feat(agent): smart loop detection for stuck agents (#49)
* feat(agent): add smart loop detection for stuck agents (#16)

Detect when agents repeat the same tool calls or text outputs in a
sliding window. Three modes: warn (inject nudge, terminate on 2nd hit),
terminate (immediate stop), or custom callback. Fully opt-in via
`loopDetection` on AgentConfig — zero overhead when unconfigured.

* fix(agent): support async onLoopDetected callbacks and prevent orphaned tool_use events

- Await onLoopDetected callback result so async functions work correctly
  instead of silently falling through to 'continue'
- Move loop detection before yielding tool_use events so terminate mode
  never emits tool_use without a matching tool_result

* fix(agent): reset loopWarned on recovery and rename maxRepeatedToolCalls to maxRepetitions

- Reset loopWarned flag when the agent stops repeating, so a future
  loop gets a fresh warning cycle instead of immediate termination
- Rename maxRepeatedToolCalls → maxRepetitions since the threshold
  applies to both tool call and text output repetition detection

* test(agent): add tests for async callback, warn recovery, and injected warning text

- Verify async onLoopDetected callback is awaited correctly
- Verify loopWarned resets after recovery, giving fresh warning cycle
- Verify WARNING TextBlock is injected into user message content
2026-04-05 13:01:53 +08:00
..
agent-hooks.test.ts feat(agent): add beforeRun / afterRun lifecycle hooks (#45) 2026-04-05 00:41:21 +08:00
approval.test.ts feat(orchestrator): add onApproval callback for human-in-the-loop (#32) 2026-04-05 02:46:20 +08:00
gemini-adapter.test.ts chore: support Node >=18, add optional @google/genai peer dependency and API key fallback 2026-04-04 22:12:28 +03:00
grok-adapter.test.ts feat(llm): add first-class Grok (xAI) support with dedicated GrokAdapter (#44) 2026-04-04 18:20:55 +08:00
loop-detection.test.ts feat(agent): smart loop detection for stuck agents (#49) 2026-04-05 13:01:53 +08:00
openai-fallback.test.ts feat(llm): add fallback tool-call extraction for local models (#15) 2026-04-05 11:49:10 +08:00
semaphore.test.ts chore: add tests, CI, contributing guide, and PR template 2026-04-02 23:43:54 +08:00
shared-memory.test.ts chore: add tests, CI, contributing guide, and PR template 2026-04-02 23:43:54 +08:00
structured-output.test.ts feat: add optional outputSchema (Zod) for structured agent output (#36) 2026-04-03 13:45:47 +08:00
task-queue.test.ts chore: add tests, CI, contributing guide, and PR template 2026-04-02 23:43:54 +08:00
task-retry.test.ts feat: task-level retry with exponential backoff (#37) 2026-04-03 14:08:36 +08:00
task-utils.test.ts chore: add tests, CI, contributing guide, and PR template 2026-04-02 23:43:54 +08:00
text-tool-extractor.test.ts feat(llm): add fallback tool-call extraction for local models (#15) 2026-04-05 11:49:10 +08:00
tool-executor.test.ts chore: add tests, CI, contributing guide, and PR template 2026-04-02 23:43:54 +08:00
trace.test.ts feat: add onTrace observability callback (#18) 2026-04-03 15:28:59 +08:00