Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5e40fe

Browse files
laststylebender14autofix-ci[bot]tusharmath
authored
fix: update conversation on each turn (tailcallhq#947)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Tushar Mathur <[email protected]>
1 parent d102347 commit b5e40fe

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

crates/forge_app/src/agent.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::sync::Arc;
22

33
use forge_domain::{
4-
Agent, ChatCompletionMessage, Context, ModelId, ResultStream, ToolCallContext, ToolCallFull,
5-
ToolResult,
4+
Agent, ChatCompletionMessage, Context, Conversation, ModelId, ResultStream, ToolCallContext,
5+
ToolCallFull, ToolResult,
66
};
77

88
use crate::tool_registry::ToolRegistry;
9-
use crate::{ProviderService, Services};
9+
use crate::{ConversationService, ProviderService, Services};
1010

1111
/// Agent service trait that provides core chat and tool call functionality.
1212
/// This trait abstracts the essential operations needed by the Orchestrator.
@@ -26,6 +26,9 @@ pub trait AgentService: Send + Sync + 'static {
2626
context: &mut ToolCallContext,
2727
call: ToolCallFull,
2828
) -> ToolResult;
29+
30+
/// Synchronize the on-going conversation
31+
async fn update(&self, conversation: Conversation) -> anyhow::Result<()>;
2932
}
3033

3134
/// Blanket implementation of AgentService for any type that implements Services
@@ -51,4 +54,8 @@ where
5154
let registry = ToolRegistry::new(Arc::new(self.clone()));
5255
registry.call(agent, context, call).await
5356
}
57+
58+
async fn update(&self, conversation: Conversation) -> anyhow::Result<()> {
59+
self.conversation_service().upsert(conversation).await
60+
}
5461
}

crates/forge_app/src/orch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ impl<S: AgentService> Orchestrator<S> {
310310
while !is_complete {
311311
// Set context for the current loop iteration
312312
self.conversation.context = Some(context.clone());
313+
self.services.update(self.conversation.clone()).await?;
313314

314315
let ChatCompletionMessageFull { tool_calls, content, mut usage } = self
315316
.environment
@@ -403,6 +404,7 @@ impl<S: AgentService> Orchestrator<S> {
403404

404405
// Update context in the conversation
405406
self.conversation.context = Some(context.clone());
407+
self.services.update(self.conversation.clone()).await?;
406408
}
407409

408410
Ok(())

0 commit comments

Comments
 (0)