Always store the entire conversation history. Request encrypted COT when not storing Responses. Send entire input context instead of sending previous_response_id
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use crate::models::ResponseItem;
|
|
|
|
/// Transcript of conversation history
|
|
#[derive(Debug, Clone, Default)]
|
|
pub(crate) struct ConversationHistory {
|
|
/// The oldest items are at the beginning of the vector.
|
|
items: Vec<ResponseItem>,
|
|
}
|
|
|
|
impl ConversationHistory {
|
|
pub(crate) fn new() -> Self {
|
|
Self { items: Vec::new() }
|
|
}
|
|
|
|
/// Returns a clone of the contents in the transcript.
|
|
pub(crate) fn contents(&self) -> Vec<ResponseItem> {
|
|
self.items.clone()
|
|
}
|
|
|
|
/// `items` is ordered from oldest to newest.
|
|
pub(crate) fn record_items<I>(&mut self, items: I)
|
|
where
|
|
I: IntoIterator,
|
|
I::Item: std::ops::Deref<Target = ResponseItem>,
|
|
{
|
|
for item in items {
|
|
if is_api_message(&item) {
|
|
// Note agent-loop.ts also does filtering on some of the fields.
|
|
self.items.push(item.clone());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Anything that is not a system message or "reasoning" message is considered
|
|
/// an API message.
|
|
fn is_api_message(message: &ResponseItem) -> bool {
|
|
match message {
|
|
ResponseItem::Message { role, .. } => role.as_str() != "system",
|
|
ResponseItem::FunctionCallOutput { .. }
|
|
| ResponseItem::FunctionCall { .. }
|
|
| ResponseItem::LocalShellCall { .. }
|
|
| ResponseItem::Reasoning { .. } => true,
|
|
ResponseItem::Other => false,
|
|
}
|
|
}
|