[PR #233] [CLOSED] feat: Oracle agent — web search with lorebook persistence #4520

Closed
opened 2026-10-22 04:08:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/233
Author: @Beherit79
Created: 4/25/2026
Status: ❌ Closed

Base: main ← Head: feat/oracle-agent


📝 Commits (3)

  • 9990c33 feat: Oracle agent — web search with lorebook persistence
  • 1dc35a0 Merge branch 'main' into feat/oracle-agent
  • 31cd40c fix(oracle): improve memory recall — LLM-produced concise keys + always-on injection

📊 Changes

22 files changed (+2042 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
📝 README.md (+2 -1)
📝 docs/CONFIGURATION.md (+20 -0)
➕ docs/ORACLE.md (+440 -0)
📝 packages/client/src/components/panels/ConnectionsPanel.tsx (+4 -0)
➕ packages/client/src/components/panels/settings/OracleConfigCard.tsx (+390 -0)
➕ packages/client/src/hooks/use-oracle.ts (+37 -0)
📝 packages/server/src/routes/generate.routes.ts (+345 -6)
📝 packages/server/src/routes/generate/lorebook-keeper-utils.ts (+18 -4)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/routes/oracle.routes.ts (+83 -0)
📝 packages/server/src/services/agents/agent-executor.ts (+29 -1)
➕ packages/server/src/services/agents/oracle.ts (+338 -0)
➕ packages/server/src/services/agents/web-search/config.ts (+53 -0)
➕ packages/server/src/services/agents/web-search/tavily-provider.ts (+81 -0)
➕ packages/server/src/services/agents/web-search/web-search-provider-factory.ts (+22 -0)
➕ packages/server/src/services/agents/web-search/web-search-provider.ts (+15 -0)
📝 packages/server/src/services/conversation/character-commands.ts (+36 -0)
📝 packages/shared/src/constants/agent-prompts.ts (+34 -0)
📝 packages/shared/src/index.ts (+1 -0)

...and 2 more files

📄 Description

Why this change

Closes #232

Characters in Marinara are currently stuck with whatever was written in their lore/card. If a user wants to roleplay around something current, e.g a real-world event, recent news, an actual schedule, there is currently no clean way to get that information into the character's context. The existing Knowledge Retrieval agent only reads from the local lorebook.

This PR adds Oracle, an opt-in pre-generation agent triggered by <search>topic</search> in a user message.

For the MVP, Oracle fetches web results through Tavily, summarises them with a strict anti-hallucination prompt, injects the summary into the current turn, and can optionally persist a post-reply takeaway as a lorebook entry tagged web-research.

The persistence step intentionally saves what the character actually committed to, what they picked, preferred, dismissed, or remembered, instead of saving raw web results. That keeps future turns useful for RP without filling the lorebook with URLs, provider snippets, or stale search output.

What changed

Server

  • Added services/agents/oracle.ts for the Oracle flow: search → summarise → takeaway extraction.
  • Added a web-search provider abstraction under services/agents/web-search/, with Tavily as the first implementation.
  • Added /api/oracle/{config,test} routes.
    • API keys are encrypted at rest with the existing crypto util.
    • GET responses return a masked key.
    • PUT preserves the stored key when the mask is sent back unchanged.
  • Updated generate.routes.ts:
    • extracts <search> triggers from the user message
    • bypasses the chat-level enableAgents gate when Oracle is explicitly user-triggered
    • runs Oracle alongside the other pre-generation agents
    • persists the post-generation takeaway when enabled
  • Updated agent-executor.ts so agents can explicitly provide settings.maxTokens.
    • Oracle uses a smaller output budget, around 600 tokens, so more input budget is available for source material.
    • The existing 16384 default floor is still preserved when no explicit value is set, so other agents should be unaffected.
  • Updated lorebook-keeper-utils.ts with a source?: { agentId, description } parameter so non-LBK agents like Oracle can attribute auto-created lorebook entries correctly.

Shared

  • Added types/oracle.ts for the Zod config schema, masked-key constant, and lorebook tag constant.
  • Updated types/agent.ts:
    • Oracle entry in BUILT_IN_AGENTS
    • Oracle entry in DEFAULT_AGENT_TOOLS
    • web_search in BUILT_IN_TOOLS
  • Added Oracle's default summariser prompt in constants/agent-prompts.ts.

Client

  • Added OracleConfigCard.tsx in the Connections panel.
    • provider
    • API key, with masked/debounced save
    • max results
    • summary token cap
    • timeout
    • auto-persist toggle
    • test button
  • Added useOracle React Query hook for config get/save/test.

Docs

  • Added docs/ORACLE.md covering the end-to-end flow, design decisions, failure modes, and known limits.
  • Updated docs/CONFIGURATION.md with an Oracle section under Agent-Specific Configuration.
  • Updated README.md to mention Oracle in the AI Agent System paragraph and Documentation table.
  • Updated CHANGELOG.md under [Unreleased] / Added.

Validation

  • pnpm check
  • Manual verification completed (described below).

Manual verification notes

  • Configured Oracle with a Tavily key. The Test button returns ok: true with a non-zero result count.
  • Sent a chat message containing <search>European rugby match this weekend</search>.
    • Server logs show:
      • [oracle] Detected 1 <search> trigger(s)
      • [oracle] Search returned 6 result(s)
      • [oracle] Summariser result — success=true
    • The character used the actual fixtures in its in-character reply.
  • After the reply, the takeaway pass either:
    • captured a single-sentence commitment, for example “X picked the Bordeaux match over Leinster…”
    • or correctly emitted NO_MEMORY (skipped) when the character only acknowledged the info without making a choice.
  • With autoPersist: true, a valid takeaway creates or reuses a lorebook entry tagged web-research, visible in the lorebook panel.
  • Disabling Oracle in the agent panel makes <search> tags pass through as plain text. No API call is made and no Oracle log line is emitted.
  • Empty or whitespace-only <search> blocks are ignored without errors.
  • A misconfigured key, for example a provider 401, logs [oracle] Search failed and the character still replies normally without injected findings.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONFIGURATION / ORACLE / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

This is a feature PR, not a release PR. I did not touch version-bearing files. The changelog entry is under [Unreleased] for maintainers to include in the next release.

UI evidence

Oracle agent entry

image - image - image - image

Settings → Connections → Oracle config card

Masked key and Test button visible.

image

Chat with <search> trigger and in-character reply

mari_search_oracle - image

No, it is not biased lol.

Lorebook entries (Uncategorized)

image - image

Lorebook entry details

Different test run from the previous screenshot.

image

Retrieval

image

Status

This PR is intended as a concrete proposal for Oracle rather than a final “this is the only shape” implementation.

The code is ready for review and manual testing passes, but I am open to changing the trigger syntax, persistence behavior, config surface, or cutting scope if maintainers prefer a smaller first version.

The issue and this PR description were written with LLM assistance. The feature itself comes from my own use case, and the implementation was manually tested in CONVO.

Summary by CodeRabbit

  • New Features

    • Oracle agent for live web search functionality
    • Trigger searches via <search>topic</search> tags in messages
    • Automatic summarization and injection into character context
    • Optional persistence of character insights to lorebook
    • Configure in Settings → Connections → Oracle
  • Documentation

    • Added Oracle agent setup and usage documentation

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/233 **Author:** [@Beherit79](https://github.com/Beherit79) **Created:** 4/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/oracle-agent` --- ### 📝 Commits (3) - [`9990c33`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9990c337371b6d1289c012ae0a7a8961d7432e30) feat: Oracle agent — web search with lorebook persistence - [`1dc35a0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1dc35a0c23039d69164c45c945c3a56fed0c2c3d) Merge branch 'main' into feat/oracle-agent - [`31cd40c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/31cd40cbb58669c73c6e4e9baf8b4e961ab4e9a8) fix(oracle): improve memory recall — LLM-produced concise keys + always-on injection ### 📊 Changes **22 files changed** (+2042 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) 📝 `README.md` (+2 -1) 📝 `docs/CONFIGURATION.md` (+20 -0) ➕ `docs/ORACLE.md` (+440 -0) 📝 `packages/client/src/components/panels/ConnectionsPanel.tsx` (+4 -0) ➕ `packages/client/src/components/panels/settings/OracleConfigCard.tsx` (+390 -0) ➕ `packages/client/src/hooks/use-oracle.ts` (+37 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+345 -6) 📝 `packages/server/src/routes/generate/lorebook-keeper-utils.ts` (+18 -4) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/routes/oracle.routes.ts` (+83 -0) 📝 `packages/server/src/services/agents/agent-executor.ts` (+29 -1) ➕ `packages/server/src/services/agents/oracle.ts` (+338 -0) ➕ `packages/server/src/services/agents/web-search/config.ts` (+53 -0) ➕ `packages/server/src/services/agents/web-search/tavily-provider.ts` (+81 -0) ➕ `packages/server/src/services/agents/web-search/web-search-provider-factory.ts` (+22 -0) ➕ `packages/server/src/services/agents/web-search/web-search-provider.ts` (+15 -0) 📝 `packages/server/src/services/conversation/character-commands.ts` (+36 -0) 📝 `packages/shared/src/constants/agent-prompts.ts` (+34 -0) 📝 `packages/shared/src/index.ts` (+1 -0) _...and 2 more files_ </details> ### 📄 Description ## Why this change Closes #232 Characters in Marinara are currently stuck with whatever was written in their lore/card. If a user wants to roleplay around something current, e.g a real-world event, recent news, an actual schedule, there is currently no clean way to get that information into the character's context. The existing Knowledge Retrieval agent only reads from the local lorebook. This PR adds **Oracle**, an opt-in pre-generation agent triggered by `<search>topic</search>` in a user message. For the MVP, Oracle fetches web results through Tavily, summarises them with a strict anti-hallucination prompt, injects the summary into the current turn, and can optionally persist a post-reply takeaway as a lorebook entry tagged `web-research`. The persistence step intentionally saves what the character actually committed to, what they picked, preferred, dismissed, or remembered, instead of saving raw web results. That keeps future turns useful for RP without filling the lorebook with URLs, provider snippets, or stale search output. ## What changed ### Server - Added `services/agents/oracle.ts` for the Oracle flow: search → summarise → takeaway extraction. - Added a web-search provider abstraction under `services/agents/web-search/`, with Tavily as the first implementation. - Added `/api/oracle/{config,test}` routes. - API keys are encrypted at rest with the existing `crypto` util. - GET responses return a masked key. - PUT preserves the stored key when the mask is sent back unchanged. - Updated `generate.routes.ts`: - extracts `<search>` triggers from the user message - bypasses the chat-level `enableAgents` gate when Oracle is explicitly user-triggered - runs Oracle alongside the other pre-generation agents - persists the post-generation takeaway when enabled - Updated `agent-executor.ts` so agents can explicitly provide `settings.maxTokens`. - Oracle uses a smaller output budget, around 600 tokens, so more input budget is available for source material. - The existing 16384 default floor is still preserved when no explicit value is set, so other agents should be unaffected. - Updated `lorebook-keeper-utils.ts` with a `source?: { agentId, description }` parameter so non-LBK agents like Oracle can attribute auto-created lorebook entries correctly. ### Shared - Added `types/oracle.ts` for the Zod config schema, masked-key constant, and lorebook tag constant. - Updated `types/agent.ts`: - Oracle entry in `BUILT_IN_AGENTS` - Oracle entry in `DEFAULT_AGENT_TOOLS` - `web_search` in `BUILT_IN_TOOLS` - Added Oracle's default summariser prompt in `constants/agent-prompts.ts`. ### Client - Added `OracleConfigCard.tsx` in the Connections panel. - provider - API key, with masked/debounced save - max results - summary token cap - timeout - auto-persist toggle - test button - Added `useOracle` React Query hook for config get/save/test. ### Docs - Added `docs/ORACLE.md` covering the end-to-end flow, design decisions, failure modes, and known limits. - Updated `docs/CONFIGURATION.md` with an Oracle section under Agent-Specific Configuration. - Updated `README.md` to mention Oracle in the AI Agent System paragraph and Documentation table. - Updated `CHANGELOG.md` under `[Unreleased] / Added`. ## Validation - [x] `pnpm check` - [x] Manual verification completed (described below). ### Manual verification notes - Configured Oracle with a Tavily key. The Test button returns `ok: true` with a non-zero result count. - Sent a chat message containing `<search>European rugby match this weekend</search>`. - Server logs show: - `[oracle] Detected 1 <search> trigger(s)` - `[oracle] Search returned 6 result(s)` - `[oracle] Summariser result — success=true` - The character used the actual fixtures in its in-character reply. - After the reply, the takeaway pass either: - captured a single-sentence commitment, for example “X picked the Bordeaux match over Leinster…” - or correctly emitted `NO_MEMORY (skipped)` when the character only acknowledged the info without making a choice. - With `autoPersist: true`, a valid takeaway creates or reuses a lorebook entry tagged `web-research`, visible in the lorebook panel. - Disabling Oracle in the agent panel makes `<search>` tags pass through as plain text. No API call is made and no Oracle log line is emitted. - Empty or whitespace-only `<search>` blocks are ignored without errors. - A misconfigured key, for example a provider 401, logs `[oracle] Search failed` and the character still replies normally without injected findings. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONFIGURATION / ORACLE / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) This is a feature PR, not a release PR. I did not touch version-bearing files. The changelog entry is under `[Unreleased]` for maintainers to include in the next release. ## UI evidence ### Oracle agent entry <img width="312" height="102" alt="image" src="https://github.com/user-attachments/assets/9b08322c-4218-4099-9320-5d88f073ac06" /> - <img width="1301" height="662" alt="image" src="https://github.com/user-attachments/assets/bb05e8bd-9369-4065-909c-bf4fbe0087d7" /> - <img width="842" height="789" alt="image" src="https://github.com/user-attachments/assets/7f54636b-2868-49d2-ae21-72705aabd1a3" /> - <img width="845" height="712" alt="image" src="https://github.com/user-attachments/assets/07521f58-c149-4f0b-a681-3d8f36ba0d88" /> ### Settings → Connections → Oracle config card Masked key and Test button visible. <img width="294" height="702" alt="image" src="https://github.com/user-attachments/assets/3e9085df-7393-4ef1-a9f4-568386589ec2" /> ### Chat with `<search>` trigger and in-character reply <img width="800" height="450" alt="mari_search_oracle" src="https://github.com/user-attachments/assets/6e839ed8-847c-4997-932e-ac2336c261b5" /> - <img width="1308" height="873" alt="image" src="https://github.com/user-attachments/assets/0ce43f8f-53a1-44f6-8d59-893f488696ee" /> _No, it is not biased lol._ ### Lorebook entries (Uncategorized) <img width="947" height="368" alt="image" src="https://github.com/user-attachments/assets/87ab5d44-429d-4851-82bc-74c2c1bcdf78" /> - <img width="874" height="347" alt="image" src="https://github.com/user-attachments/assets/40985351-d68a-44a0-81fc-16a524448d7d" /> ### Lorebook entry details Different test run from the previous screenshot. <img width="867" height="927" alt="image" src="https://github.com/user-attachments/assets/e61c3891-333b-4213-9e1b-b980d2dcec8b" /> ### Retrieval <img width="902" height="262" alt="image" src="https://github.com/user-attachments/assets/f1bda82a-4709-4b64-9a30-83d7573a7455" /> ## Status This PR is intended as a concrete proposal for Oracle rather than a final “this is the only shape” implementation. The code is ready for review and manual testing passes, but I am open to changing the trigger syntax, persistence behavior, config surface, or cutting scope if maintainers prefer a smaller first version. The issue and this PR description were written with LLM assistance. The feature itself comes from my own use case, and the implementation was manually tested in CONVO. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Oracle agent for live web search functionality * Trigger searches via `<search>topic</search>` tags in messages * Automatic summarization and injection into character context * Optional persistence of character insights to lorebook * Configure in Settings → Connections → Oracle * **Documentation** * Added Oracle agent setup and usage documentation <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4520
No description provided.