mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
feat: add per-route message dispatch modes (inject/parallel/queue)
Introduce three inbound message handling modes for channel adapters: - inject (default, /btw): when a route has an active agent stream, inject the new user message into the running stream via the SDK's PrepareStep hook between tool rounds. The message is interleaved at the correct position in the persisted round. - parallel (/now): start a new agent stream immediately, running concurrently with any existing stream (preserves current behavior). - queue (/next): enqueue the message and process it after the current stream completes. Key components: - RouteDispatcher: per-route state management with inject channel, task queue, and active-stream tracking. - PrepareStep integration: drains inject channel between tool rounds, records insertion position via InjectedRecorder for correct persistence ordering. - interleaveInjectedMessages: inserts injected user messages at their actual injection position within the persisted message round. - Parallel mode isolation: /now streams do not interact with the dispatcher, preventing them from clearing another stream's active state.
This commit is contained in:
@@ -46,6 +46,13 @@ type LoopDetectionConfig struct {
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
// InjectMessage carries a user message to be injected into a running agent
|
||||
// stream between tool rounds via the PrepareStep hook.
|
||||
type InjectMessage struct {
|
||||
Text string
|
||||
HeaderifiedText string
|
||||
}
|
||||
|
||||
// RunConfig holds everything needed for a single agent invocation.
|
||||
type RunConfig struct {
|
||||
Model *sdk.Model
|
||||
@@ -60,6 +67,17 @@ type RunConfig struct {
|
||||
Identity SessionContext
|
||||
Skills []SkillEntry
|
||||
LoopDetection LoopDetectionConfig
|
||||
|
||||
// InjectCh receives user messages to inject between tool rounds.
|
||||
// When non-nil, a PrepareStep hook drains this channel and appends
|
||||
// user messages to the conversation before the next LLM call.
|
||||
InjectCh <-chan InjectMessage
|
||||
|
||||
// InjectedRecorder is called each time a message is injected via
|
||||
// PrepareStep, recording the headerified text and the number of SDK
|
||||
// output messages that preceded the injection. Used by the resolver
|
||||
// to interleave injected messages at the correct position in storeRound.
|
||||
InjectedRecorder func(headerifiedText string, insertAfter int)
|
||||
}
|
||||
|
||||
// GenerateResult holds the result of a non-streaming agent invocation.
|
||||
|
||||
Reference in New Issue
Block a user