Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore(ai): improve tracing and prompt (#2004)
Eric Hayes6c47c69ef511
diff --git a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md b/rust/cloud-storage/ai_tools/src/prompts/all_tools.mdindex 447885506c..2221c4a9c6 100644--- a/rust/cloud-storage/ai_tools/src/prompts/all_tools.md+++ b/rust/cloud-storage/ai_tools/src/prompts/all_tools.md@@ -123,8 +123,9 @@ If no inline or node ids are present:returns anything relavent. IMPORTANT- IMPORTANT: The code execution tools (`bash_code_execution`, and `text_editor_code_execution`) should only be used-when the user asks you to _execute_ code or asks you to do a task that is best done with code ie compute std dev,-draw a chart, create a pdf, or some other task that can't be completed with any other tool. DO NOT confuse `text_editor_code_execution` tool+when the user explicitely asks you to _execute_ code.++- DO NOT confuse `text_editor_code_execution` tool(which creates a file for the code execution environment) for the `CreateDocument` tool which creates a document in theusers workspace. If the user asks you to create a document, write a code file, or create any file you should use the `CreateDocument` tool.diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history.rsindex 71b3d76079..7a95bf0a04 100644--- a/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history.rs@@ -1,4 +1,4 @@-use axum::extract::{Path, State};+use axum::extract::{Extension, Path, State};use axum::{Json,http::StatusCode,@@ -7,6 +7,7 @@ use axum::{use macro_db_client::chat_history::get_chat_history;use macro_middleware::cloud_storage::ensure_access::chat::ChatAccessLevelExtractor;use model::chat::ChatHistory;+use model::user::UserContext;use models_permissions::share_permission::access_level::ViewAccessLevel;use sqlx::PgPool;@@ -23,9 +24,10 @@ use sqlx::PgPool;(status = 500, body = String, description = "Internal server error")))]-#[tracing::instrument(skip(db), fields(chat_id=?chat_id))]+#[tracing::instrument(skip(db, user_context), fields(chat_id = %chat_id, user_id = %user_context.user_id))]pub async fn get_chat_history_handler(_access: ChatAccessLevelExtractor<ViewAccessLevel>,+ Extension(user_context): Extension<UserContext>,State(db): State<PgPool>,Path(chat_id): Path<String>,) -> Result<Json<ChatHistory>, Response> {diff --git a/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history_batch_messages.rs b/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history_batch_messages.rsindex c3577d7015..62fefbc836 100644--- a/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history_batch_messages.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/chats/chat_history_batch_messages.rs@@ -25,7 +25,7 @@ use sqlx::PgPool;(status = 500, body = String, description = "Internal server error")))]-#[tracing::instrument(skip(db, user_context), fields(user_id=?user_context.user_id))]+#[tracing::instrument(skip(db, user_context, request), fields(user_id = %user_context.user_id, message_count = request.message_ids.len()))]pub async fn get_chat_history_batch_messages_handler(State(db): State<PgPool>,Extension(user_context): Extension<UserContext>,diff --git a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rsindex 70b3f9596d..4b50ca2b4b 100644--- a/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs+++ b/rust/cloud-storage/document_cognition_service/src/api/stream/chat_message.rs@@ -124,7 +124,7 @@ impl IntoResponse for ChatMessageError {(status = 403, description = "Forbidden"),))]-#[tracing::instrument(skip(state, user_context, bearer, request), fields(chat_id=?request.chat_id, attachment_ids=?request.attachments.as_ref().map(|a| a.iter().map(|att| att.attachment_id.as_str()).collect::<Vec<_>>()).unwrap_or_default()), ret, err)]+#[tracing::instrument(skip(state, user_context, bearer, request), fields(chat_id=?request.chat_id, user_id = %user_context.user_id, attachment_ids=?request.attachments.as_ref().map(|a| a.iter().map(|att| att.attachment_id.as_str()).collect::<Vec<_>>()).unwrap_or_default()), ret, err)]pub async fn send_chat_message(State(state): State<ApiContext>,Extension(user_context): Extension<UserContext>,@@ -378,7 +378,7 @@ fn stream_and_save_message({Ok(stream) => stream,Err(e) => {- tracing::error!(error=?e, "failed to create AI stream");+ tracing::error!(error=?e, chat_id = %chat_id, user_id = %user_id, stream_id = %stream_id, "failed to create AI stream");let stream_error = match e {ai::types::AiError::ContextWindowExceeded => {StreamError::ModelContextOverflow {@@ -402,7 +402,7 @@ fn stream_and_save_message(while let Some(response) = match tokio::time::timeout(idle_timeout, ai_stream.next()).await {Ok(item) => item,Err(_) => {- tracing::error!("AI stream idle timeout: no token received within {idle_timeout:?}");+ tracing::error!(chat_id = %chat_id, user_id = %user_id, stream_id = %stream_id, "AI stream idle timeout: no token received within {idle_timeout:?}");let stream_error = StreamError::InternalError {stream_id: stream_id.clone(),};@@ -466,7 +466,7 @@ fn stream_and_save_message(}}Err(e) => {- tracing::error!(error=?e, "error in AI stream");+ tracing::error!(error=?e, chat_id = %chat_id, user_id = %user_id, stream_id = %stream_id, "error in AI stream");// Map error type to appropriate StreamErrorlet stream_error = match e {ai::types::AiError::ContextWindowExceeded => {@@ -516,7 +516,7 @@ fn stream_and_save_message().await{- tracing::error!(error=?err, "failed to store conversation messages");+ tracing::error!(error=?err, chat_id = %chat_id, user_id = %user_id, stream_id = %stream_id, "failed to store conversation messages");}// Summarize and send notification in a background task