Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/forge_app/src/agent_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ impl<S: Services> AgentExecutor<S> {
.await?;

// Create a new conversation for agent execution
let conversation = Conversation::generate().title(task.clone());
// Create context with agent initiator since it's spawned by a parent agent
let context = forge_domain::Context::default().initiator("agent".to_string());
let conversation = Conversation::generate()
.title(task.clone())
.context(context.clone());
self.services
.conversation_service()
.upsert_conversation(conversation.clone())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

Request::try_from(context).unwrap()
Expand Down
2 changes: 2 additions & 0 deletions crates/forge_app/src/dto/anthropic/transforms/set_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = Request::try_from(context).expect("Failed to convert context to request");
Expand Down Expand Up @@ -239,6 +240,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = Request::try_from(context).expect("Failed to convert context to request");
Expand Down
5 changes: 5 additions & 0 deletions crates/forge_app/src/dto/openai/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ pub struct Request {
pub parallel_tool_calls: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
/// Indicates who initiated the conversation: "user" or "agent".
/// Used for GitHub Copilot billing optimization. Not serialized to API.
#[serde(skip_serializing)]
pub initiator: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stream_options: Option<StreamOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -400,6 +404,7 @@ impl From<Context> for Request {
* on model capabilities */
stream_options: Some(StreamOptions { include_usage: Some(true) }),
session_id: context.conversation_id.map(|id| id.to_string()),
initiator: context.initiator,
reasoning: context.reasoning,
reasoning_effort: Default::default(),
max_completion_tokens: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = Request::from(context);
Expand Down
1 change: 1 addition & 0 deletions crates/forge_app/src/dto/openai/transformers/set_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = Request::from(context);
Expand Down
4 changes: 4 additions & 0 deletions crates/forge_domain/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ impl std::ops::DerefMut for MessageEntry {
pub struct Context {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub conversation_id: Option<ConversationId>,
/// Indicates who initiated the conversation: "user" or "agent".
/// Used for GitHub Copilot billing optimization.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub initiator: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub messages: Vec<MessageEntry>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down
4 changes: 4 additions & 0 deletions crates/forge_repo/src/conversation/conversation_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ impl From<ReasoningConfigRecord> for forge_domain::ReasoningConfig {
pub(super) struct ContextRecord {
#[serde(default, skip_serializing_if = "Option::is_none")]
conversation_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
initiator: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
messages: Vec<ContextMessageRecord>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand All @@ -748,6 +750,7 @@ impl From<&Context> for ContextRecord {
fn from(context: &Context) -> Self {
Self {
conversation_id: context.conversation_id.as_ref().map(|id| id.into_string()),
initiator: context.initiator.clone(),
messages: context
.messages
.iter()
Expand Down Expand Up @@ -803,6 +806,7 @@ impl TryFrom<ContextRecord> for Context {

Ok(Context {
conversation_id,
initiator: record.initiator,
messages: messages?,
tools: tools?,
tool_choice: record.tool_choice.map(Into::into),
Expand Down
4 changes: 4 additions & 0 deletions crates/forge_repo/src/provider/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@ mod tests {

let fixture = Context {
conversation_id: None,
initiator: None,
messages: vec![
ContextMessage::system("You are a helpful assistant").into(),
ContextMessage::Text(TextMessage::new(Role::User, "Hello!")).into(),
Expand Down Expand Up @@ -1701,6 +1702,7 @@ mod tests {

let fixture = Context {
conversation_id: None,
initiator: None,
messages: vec![],
tools: vec![],
tool_choice: None,
Expand All @@ -1726,6 +1728,7 @@ mod tests {

let fixture = Context {
conversation_id: None,
initiator: None,
messages: vec![],
tools: vec![],
tool_choice: None,
Expand Down Expand Up @@ -1759,6 +1762,7 @@ mod tests {

let fixture = Context {
conversation_id: None,
initiator: None,
messages: vec![],
tools: vec![],
tool_choice: None,
Expand Down
3 changes: 3 additions & 0 deletions crates/forge_repo/src/provider/bedrock_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = ConverseStreamInput::from_domain(context).expect("Failed to convert context");
Expand Down Expand Up @@ -130,6 +131,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = ConverseStreamInput::from_domain(context).expect("Failed to convert context");
Expand Down Expand Up @@ -159,6 +161,7 @@ mod tests {
reasoning: None,
stream: None,
response_format: None,
initiator: None,
};

let request = ConverseStreamInput::from_domain(context).expect("Failed to convert context");
Expand Down
Loading
Loading