feat(agent): deliver LLM text content synchronously when tool calls are present
This commit is contained in:
parent
187b2c2185
commit
eca076c094
1 changed files with 18 additions and 0 deletions
|
|
@ -2232,6 +2232,24 @@ turnLoop:
|
||||||
ts.recordPersistedMessage(assistantMsg)
|
ts.recordPersistedMessage(assistantMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When the LLM returns both text content and tool calls in the
|
||||||
|
// same response, deliver the text to the user synchronously
|
||||||
|
// before executing tools. This must use channelManager.SendMessage
|
||||||
|
// (synchronous) rather than bus.PublishOutbound (async) so the
|
||||||
|
// placeholder is consumed before preSendMedia can delete it.
|
||||||
|
if response.Content != "" && al.channelManager != nil && ts.channel != "" && !constants.IsInternalChannel(ts.channel) {
|
||||||
|
// Strip split markers since SendMessage bypasses the worker
|
||||||
|
// loop where SplitByMarker normally runs.
|
||||||
|
contentParts := channels.SplitByMarker(response.Content)
|
||||||
|
for _, part := range contentParts {
|
||||||
|
_ = al.channelManager.SendMessage(ctx, bus.OutboundMessage{
|
||||||
|
Channel: ts.channel,
|
||||||
|
ChatID: ts.chatID,
|
||||||
|
Content: part,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ts.setPhase(TurnPhaseTools)
|
ts.setPhase(TurnPhaseTools)
|
||||||
for i, tc := range normalizedToolCalls {
|
for i, tc := range normalizedToolCalls {
|
||||||
if ts.hardAbortRequested() {
|
if ts.hardAbortRequested() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue