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
12 changes: 12 additions & 0 deletions crates/agentic-core/migrations/0002_add_placeholders.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ALTER TABLE conversations ADD COLUMN tenant_id TEXT;
ALTER TABLE conversations ADD COLUMN metadata TEXT;

ALTER TABLE items ADD COLUMN tenant_id TEXT;
ALTER TABLE items ADD COLUMN raw_tokens TEXT;

ALTER TABLE responses ADD COLUMN tenant_id TEXT;
ALTER TABLE responses ADD COLUMN raw_tokens TEXT;

CREATE INDEX IF NOT EXISTS idx_conversations_tenant_id ON conversations (tenant_id);
CREATE INDEX IF NOT EXISTS idx_items_tenant_id ON items (tenant_id);
CREATE INDEX IF NOT EXISTS idx_responses_tenant_id ON responses (tenant_id);
5 changes: 5 additions & 0 deletions crates/agentic-core/src/storage/models/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct Conversation {
/// Unique conversation identifier.
pub id: String,

/// Optional metadata as JSON string.
pub metadata: Option<String>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franciscojavierarceo is this metadata different than the one stored in response table? if not I think we dont need it here cause the information already exist in response table

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/// Creation timestamp as Unix timestamp in seconds.
pub created_at: i64,
}
Expand Down Expand Up @@ -69,10 +72,12 @@ mod tests {
fn test_conversation_basic() {
let conversation = Conversation {
id: "conv_1".to_string(),
metadata: None,
created_at: 1_704_067_200,
};

assert_eq!(conversation.id, "conv_1");
assert!(conversation.metadata.is_none());
assert_eq!(conversation.created_at, 1_704_067_200);
}
}
13 changes: 10 additions & 3 deletions crates/agentic-core/src/storage/models/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Conversation history item stored in the database.

use tracing::warn;

use super::super::pool::{DbPool, DbResult, DbTransaction};
use super::super::types::item::InOutItem;
use crate::types::io::{InputItem, OutputItem};
Expand Down Expand Up @@ -44,9 +46,14 @@ impl Item {
/// Deserialize data column as either `InputItem` or `OutputItem`.
#[must_use]
pub fn as_inout(&self) -> Option<InOutItem> {
self.as_input()
.map(InOutItem::Input)
.or_else(|| self.as_output().map(InOutItem::Output))
match (self.as_input(), self.as_output()) {
(Some(input), _) if !matches!(input, InputItem::Unknown) => Some(InOutItem::Input(input)),
(_, Some(output)) if !matches!(output, OutputItem::Unknown) => Some(InOutItem::Output(output)),
_ => {
warn!(item_id = %self.id, "unrecognized item type in stored data");
None
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/agentic-core/src/storage/types/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use super::super::models::Conversation as StorageDbConversation;
pub struct ConversationData {
/// Unique conversation identifier
pub conversation_id: String,
/// Optional metadata as JSON string
pub metadata: Option<String>,
/// Creation timestamp as Unix timestamp in seconds
pub created_at: i64,
}
Expand All @@ -17,6 +19,7 @@ impl From<StorageDbConversation> for ConversationData {
fn from(row: StorageDbConversation) -> Self {
Self {
conversation_id: row.id,
metadata: row.metadata,
created_at: row.created_at,
}
}
Expand All @@ -26,6 +29,7 @@ impl From<ConversationData> for StorageDbConversation {
fn from(data: ConversationData) -> Self {
Self {
id: data.conversation_id,
metadata: data.metadata,
created_at: data.created_at,
}
}
Expand All @@ -39,6 +43,7 @@ mod tests {
fn test_conversation_from_db_conversation() {
let db_row = StorageDbConversation {
id: "conv_123".to_string(),
metadata: None,
created_at: 1_704_067_200,
};

Expand All @@ -51,18 +56,21 @@ mod tests {
fn test_conversation_roundtrip() {
let data = ConversationData {
conversation_id: "conv_456".to_string(),
metadata: Some(r#"{"key":"value"}"#.to_string()),
created_at: 1_704_067_200,
};

let db_row: StorageDbConversation = data.into();
assert_eq!(db_row.id, "conv_456");
assert_eq!(db_row.metadata, Some(r#"{"key":"value"}"#.to_string()));
assert_eq!(db_row.created_at, 1_704_067_200);
}

#[test]
fn test_conversation_data_clone() {
let data = ConversationData {
conversation_id: "conv_clone".to_string(),
metadata: None,
created_at: 1_704_067_200,
};

Expand All @@ -75,6 +83,7 @@ mod tests {
fn test_conversation_data_debug_format() {
let data = ConversationData {
conversation_id: "conv_debug".to_string(),
metadata: None,
created_at: 1_704_067_200,
};

Expand All @@ -87,6 +96,7 @@ mod tests {
fn test_conversation_bidirectional_conversion() {
let original = ConversationData {
conversation_id: "conv_bidir".to_string(),
metadata: None,
created_at: 1_706_790_600,
};

Expand Down
4 changes: 4 additions & 0 deletions crates/agentic-core/src/types/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum InputItem {
Message(InputMessage),
#[serde(rename = "function_call_output")]
FunctionCallOutput(FunctionToolResultMessage),
#[serde(other)]
Unknown,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -108,6 +110,8 @@ pub enum OutputItem {
Message(OutputMessage),
#[serde(rename = "function_call")]
FunctionCall(FunctionToolCall),
#[serde(other)]
Unknown,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
Expand Down