[GH-ISSUE #778] [Feature]: Expose pre-generation injections and parallel agent results to opt-in post-processing custom agents #377

Closed
opened 2026-10-20 17:28:09 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @Alatheus1 on GitHub (May 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/778

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

Marinara's AgentContext for post-processing custom agents currently includes the base context and the main model's response, but not the pre-generation injections or parallel-phase results from the same turn. That means a post-processor that needs data a pre-gen or parallel agent already produced has to re-fetch / re-compute it.

For agents that drive tool-heavy retrieval (RAG against an external source, fetching external data via a webhook), this is duplicate tool calls, duplicate tokens, and divergence risk — the second pull may rank or expand differently than the first.

A concrete case: a pre-gen "vault searcher" agent calls a webhook tool to fetch character-creation rules from a user's note system and emits a context_injection for the main model. A separate post-processing agent watches the assistant's response, detects when a new named character was introduced, and authors a character sheet using those rules. Today the post-processor has to repeat the full tool-call loop the pre-gen agent already did. With access to the pre-gen injection, it could reuse the work directly.

Proposed solution

Two opt-in agent settings, both defaulting to false so existing agents are unaffected:

  • settings.includePreGenInjections: true — populates a new field on AgentContext (e.g. preGenInjections: AgentInjection[]) with the current turn's pre-generation injections when the post-processing (or parallel) agent runs.
  • settings.includeParallelResults: true — same idea for the parallel-phase AgentResult[].
  • Implementation hint: agent-pipeline.ts already collects both arrays as part of createAgentPipeline — preGenerate() returns the injections and runParallel returns the results. The change is plumbing them through to post-processing agent invocations whose settings opt in, plus adding the optional fields to AgentContext.

Alternatives considered

  1. Marinara's memory as a side channel. Pre-gen agent writes to memory._someKey, post-processor reads from it. Works today but is per-chat persistent (not per-turn), keys aren't typed or discoverable, and it bypasses the normal agent data-flow contract.
  2. Re-run the tools in the post-processor. Costs tokens, costs latency, and the second pull may produce different results — different ranker decisions, different multi-query expansion, different cosine ordering — which makes the post-processor inconsistent with what the main model actually saw.
  3. Have the pre-gen agent put the data into the main response prompt so the post-processor sees it indirectly via the response text. Pollutes user-facing output with internal scaffolding and only works if the main model verbatim-includes the data (rare).

The native solution is cleaner than all three. The data is already collected upstream of the post-processing phase — it just isn't exposed.

Additional context

This came up while building a Marinara-Engine integration that uses a pre-gen custom agent to pull external knowledge into context. The agent works well in isolation (obsidian_vault_searcher, marinara-obsidian-relay), but designing a sibling post-processing agent that authors derived content from the same source meant either duplicating the lookups or going through memory. Neither felt right for a pattern that I expect is general — pre-gen retrieves, post-processor uses what was retrieved.

The opt-in default keeps surface area small. The change should be additive on AgentContext (existing destructuring patterns won't break). I'm happy to put up a PR if the proposal lands well, but wanted to confirm direction first.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Alatheus1 on GitHub (May 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/778 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? Marinara's AgentContext for post-processing custom agents currently includes the base context and the main model's response, but not the pre-generation injections or parallel-phase results from the same turn. That means a post-processor that needs data a pre-gen or parallel agent already produced has to re-fetch / re-compute it. For agents that drive tool-heavy retrieval (RAG against an external source, fetching external data via a webhook), this is duplicate tool calls, duplicate tokens, and divergence risk — the second pull may rank or expand differently than the first. A concrete case: a pre-gen "vault searcher" agent calls a webhook tool to fetch character-creation rules from a user's note system and emits a context_injection for the main model. A separate post-processing agent watches the assistant's response, detects when a new named character was introduced, and authors a character sheet using those rules. Today the post-processor has to repeat the full tool-call loop the pre-gen agent already did. With access to the pre-gen injection, it could reuse the work directly. ## Proposed solution Two opt-in agent settings, both defaulting to false so existing agents are unaffected: - settings.includePreGenInjections: true — populates a new field on AgentContext (e.g. preGenInjections: AgentInjection[]) with the current turn's pre-generation injections when the post-processing (or parallel) agent runs. - settings.includeParallelResults: true — same idea for the parallel-phase AgentResult[]. - Implementation hint: agent-pipeline.ts already collects both arrays as part of createAgentPipeline — preGenerate() returns the injections and runParallel returns the results. The change is plumbing them through to post-processing agent invocations whose settings opt in, plus adding the optional fields to AgentContext. ## Alternatives considered 1. Marinara's memory as a side channel. Pre-gen agent writes to memory._someKey, post-processor reads from it. Works today but is per-chat persistent (not per-turn), keys aren't typed or discoverable, and it bypasses the normal agent data-flow contract. 2. Re-run the tools in the post-processor. Costs tokens, costs latency, and the second pull may produce different results — different ranker decisions, different multi-query expansion, different cosine ordering — which makes the post-processor inconsistent with what the main model actually saw. 3. Have the pre-gen agent put the data into the main response prompt so the post-processor sees it indirectly via the response text. Pollutes user-facing output with internal scaffolding and only works if the main model verbatim-includes the data (rare). The native solution is cleaner than all three. The data is already collected upstream of the post-processing phase — it just isn't exposed. ## Additional context This came up while building a Marinara-Engine integration that uses a pre-gen custom agent to pull external knowledge into context. The agent works well in isolation (obsidian_vault_searcher, [marinara-obsidian-relay](https://github.com/Alatheus1/marinara-obsidian-relay)), but designing a sibling post-processing agent that authors derived content from the same source meant either duplicating the lookups or going through memory. Neither felt right for a pattern that I expect is general — pre-gen retrieves, post-processor uses what was retrieved. The opt-in default keeps surface area small. The change should be additive on AgentContext (existing destructuring patterns won't break). I'm happy to put up a PR if the proposal lands well, but wanted to confirm direction first. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@cha1latte commented on GitHub (May 13, 2026):

Triage note: labeling this as scope-risk because the request is strongly aligned with Marinara's custom-agent workflow, but it changes the AgentContext data contract and exposes cross-phase pipeline data that needs an explicit product/API decision.

The least risky next step is to confirm the first supported slice, likely opt-in post-processing access only, before plumbing broader parallel-phase result sharing.

<!-- gh-comment-id:4443731237 --> @cha1latte commented on GitHub (May 13, 2026): Triage note: labeling this as `scope-risk` because the request is strongly aligned with Marinara's custom-agent workflow, but it changes the AgentContext data contract and exposes cross-phase pipeline data that needs an explicit product/API decision. The least risky next step is to confirm the first supported slice, likely opt-in post-processing access only, before plumbing broader parallel-phase result sharing.
Author
Owner

@SpicyMarinara commented on GitHub (May 17, 2026):

We'll do the least risky implementation for now.

<!-- gh-comment-id:4470037813 --> @SpicyMarinara commented on GitHub (May 17, 2026): We'll do the least risky implementation for now.
Author
Owner

@SpicyMarinara commented on GitHub (May 17, 2026):

Implemented on staging in 4c002caa. Custom post-processing agents now have opt-in Turn Data Access controls for current-turn pre-generation injections and parallel agent results. The pipeline keeps those fields out of existing agents by default and splits post-processing batches by the opt-in flags so mixed batches do not leak context.

<!-- gh-comment-id:4470330838 --> @SpicyMarinara commented on GitHub (May 17, 2026): Implemented on staging in 4c002caa. Custom post-processing agents now have opt-in Turn Data Access controls for current-turn pre-generation injections and parallel agent results. The pipeline keeps those fields out of existing agents by default and splits post-processing batches by the opt-in flags so mixed batches do not leak context.
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#377
No description provided.