diff --git a/src/khoj/processor/conversation/anthropic/anthropic_chat.py b/src/khoj/processor/conversation/anthropic/anthropic_chat.py index 1c3b7166..4885c1a2 100644 --- a/src/khoj/processor/conversation/anthropic/anthropic_chat.py +++ b/src/khoj/processor/conversation/anthropic/anthropic_chat.py @@ -35,7 +35,7 @@ def anthropic_send_message_to_model( """ Send message to model """ - # Get Response from GPT. Don't use response_type because Anthropic doesn't support it. + # Get response from model. Don't use response_type because Anthropic doesn't support it. return anthropic_completion_with_backoff( messages=messages, system_prompt="", diff --git a/src/khoj/processor/conversation/anthropic/utils.py b/src/khoj/processor/conversation/anthropic/utils.py index 97175253..2842a270 100644 --- a/src/khoj/processor/conversation/anthropic/utils.py +++ b/src/khoj/processor/conversation/anthropic/utils.py @@ -129,6 +129,14 @@ def anthropic_completion_with_backoff( if item.type == "tool_use" ] if tool_calls: + # If there are tool calls, aggregate thoughts and responses into thoughts + if thoughts and aggregated_response: + # wrap each line of thought in italics + thoughts = "\n".join([f"*{line.strip()}*" for line in thoughts.splitlines() if line.strip()]) + thoughts = f"{thoughts}\n\n{aggregated_response}" + else: + thoughts = thoughts or aggregated_response + # Json dump tool calls into aggregated response aggregated_response = json.dumps(tool_calls) # If response schema is used, return the first tool call's input elif response_schema: