Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Response duplication when using ChatAnthropic with langgraph #1227

Closed
masato-io opened this issue Nov 27, 2024 · 6 comments
Closed

bug: Response duplication when using ChatAnthropic with langgraph #1227

masato-io opened this issue Nov 27, 2024 · 6 comments

Comments

@masato-io
Copy link

masato-io commented Nov 27, 2024

Hi 👋 Thank you for creating this fantastic library! It looks promising. I had one follow-up question regarding langgraph integration using the Anthropic model.

I was following this guide:
https://www.assistant-ui.com/docs/runtimes/langgraph#new-project-from-template

with this langgraph starter:
https://github.com/langchain-ai/react-agent-js

It works great, and everything works as expected with the OpenAI model, such as:

  const model = new ChatOpenAI({
    model: "gpt-4o",
  }).bindTools(tools);
image

But if I switch the model to:

  const model = new ChatAnthropic({
    model: "claude-3-5-sonnet-20241022",
  }).bindTools(tools);

Response from AI duplicates as attached image (there are two "Let me help..." blocks.):

image

Which blocks using assistant-ui with langgraph & Anthropic combination. Is there any way to fix this issue by any chance?

@masato-io
Copy link
Author

diff --git a/packages/react-langgraph/src/useLangGraphRuntime.ts b/packages/react-langgraph/src/useLangGraphRuntime.ts
index 5b2b5ae0..2da681e3 100644
--- a/packages/react-langgraph/src/useLangGraphRuntime.ts
+++ b/packages/react-langgraph/src/useLangGraphRuntime.ts
@@ -92,6 +92,34 @@ export const useLangGraphRuntime = ({
     stream,
   });
 
+  // Add message deduplication logic with content-based comparison for AI messages
+  const dedupedMessages = messages.filter((msg, index, self) => {
+    // Find the first message that matches these criteria
+    return (
+      index ===
+      self.findIndex((m) => {
+        // For non-AI messages, compare type and ID
+        if (msg.type !== "ai") {
+          return m.type === msg.type && m.id === msg.id;
+        }
+
+        // For AI messages, compare content regardless of ID
+        if (m.type === "ai" && msg.type === "ai") {
+          const msgContent = Array.isArray(msg.content)
+            ? msg.content[0]?.text
+            : msg.content;
+          const mContent = Array.isArray(m.content)
+            ? m.content[0]?.text
+            : m.content;
+
+          return msgContent === mContent;
+        }
+
+        return false;
+      })
+    );
+  });
+
   const [isRunning, setIsRunning] = useState(false);
   const handleSendMessage = async (messages: LangChainMessage[]) => {
     try {
@@ -106,7 +134,7 @@ export const useLangGraphRuntime = ({
 
   const threadMessages = useExternalMessageConverter({
     callback: convertLangchainMessages,
-    messages,
+    messages: dedupedMessages,
     isRunning,
   });

For now I'm band-aiding with yalc above, but couldn't get to the root cause 🙏

@Yonom
Copy link
Owner

Yonom commented Nov 28, 2024

@masato-io could you open the network tab in your browser, make a request, and share here the full response stream from langgraph? that should help me troubleshoot and fix this error

Thanks a lot for reporting this!

@masato-io
Copy link
Author

masato-io commented Nov 28, 2024

@Yonom of course, here is the stream comparison with ChatAnthropic and ChatOpenAI:

with:

  const model = new ChatAnthropic({
    model: "claude-3-5-sonnet-20241022",
  }).bindTools(tools);
curl 'http://localhost:58315/threads/94ca1fa9-5ec6-4195-b36b-b1ba47762593/runs/stream' \
  -H 'Accept: */*' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'DNT: 1' \
  -H 'Origin: http://localhost:3000' \
  -H 'Pragma: no-cache' \
  -H 'Referer: http://localhost:3000/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Chromium";v="131", "Not_A Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw '{"input":{"messages":[{"type":"human","content":"hello"}]},"stream_mode":"messages","assistant_id":"547f1faf-1f9a-4939-a920-f0f6dce76dd5"}'
event: metadata
data: {"run_id":"1efad3cd-88bc-61fb-b67a-971f6b92e28b","attempt":1}

event: messages/complete
data: [{"content":"hello","additional_kwargs":{},"response_metadata":{},"id":"da86d1e8-0685-47f4-8fee-343fe9f29696","type":"human"},{"content":[{"index":0,"type":"text","text":"Hello! I'm here to help you with Gmail-related tasks and searches. Since you haven't made a specific request yet, let me know what you'd like to do. I can help you with:\n\n1. Sending or drafting emails\n2. Managing your Gmail labels\n3. Searching through your emails\n4. Fetching specific messages or threads\n5. Managing attachments\n6. Getting profile information\n7. And more!\n\nWhat would you like to do?"}],"additional_kwargs":{"id":"msg_0114fG52zjN8JudjSxTswpwc","type":"message","role":"assistant","model":"claude-3-5-sonnet-20241022","stop_reason":"end_turn","stop_sequence":null},"response_metadata":{},"tool_call_chunks":[],"id":"msg_0114fG52zjN8JudjSxTswpwc","tool_calls":[],"invalid_tool_calls":[],"type":"ai"},{"content":"hello","additional_kwargs":{},"response_metadata":{},"id":"42b88b4c-8d8d-4224-84cd-2e550c9cbf2d","type":"human"},{"content":[{"index":0,"type":"text","text":"Hello again! I'm here to help but I'll need to know what specific task you'd like to accomplish. Could you please let me know what you'd like to do? For example:\n\n- Would you like to send an email?\n- Do you need to search for specific emails?\n- Would you like to manage your Gmail labels?\n- Do you need help with email attachments?\n- Or something else?\n\nPlease provide more details about what you'd like to do, and I'll be happy to assist you!"}],"additional_kwargs":{"id":"msg_01DeM5jXQeVbwoSXnyBkDEXp","type":"message","role":"assistant","model":"claude-3-5-sonnet-20241022","stop_reason":"end_turn","stop_sequence":null},"response_metadata":{},"tool_call_chunks":[],"id":"msg_01DeM5jXQeVbwoSXnyBkDEXp","tool_calls":[],"invalid_tool_calls":[],"type":"ai"},{"content":"hello","additional_kwargs":{},"response_metadata":{},"id":"771f8b5f-c7f2-47a6-bf30-60cce37f6aae","type":"human"}]

event: messages/metadata
data: {"msg_01CaPVGfmUsXUgzxFt3SAy7i":{"metadata":{"graph_id":"agent","run_attempt":1,"langgraph_version":"0.2.53","langgraph_plan":"developer","langgraph_host":"self-hosted","run_id":"1efad3cd-88bc-61fb-b67a-971f6b92e28b","user_id":"","thread_id":"94ca1fa9-5ec6-4195-b36b-b1ba47762593","assistant_id":"547f1faf-1f9a-4939-a920-f0f6dce76dd5","langgraph_step":7,"langgraph_node":"callModel","langgraph_triggers":["__start__:callModel"],"langgraph_path":["__pregel_pull","callModel"],"langgraph_checkpoint_ns":"callModel:80d82f42-3397-51f8-947a-90cd25a99a6e","__pregel_resuming":false,"__pregel_task_id":"80d82f42-3397-51f8-947a-90cd25a99a6e","checkpoint_ns":"callModel:80d82f42-3397-51f8-947a-90cd25a99a6e","ls_provider":"anthropic","ls_model_name":"claude-3-5-sonnet-20241022","ls_model_type":"chat","ls_temperature":1,"ls_max_tokens":2048}}}

event: messages/partial
data: [{"content":[],"additional_kwargs":{"id":"msg_01CaPVGfmUsXUgzxFt3SAy7i","type":"message","role":"assistant","model":"claude-3-5-sonnet-20241022"},"tool_call_chunks":[],"usage_metadata":{"input_tokens":4212,"output_tokens":1,"total_tokens":4213},"response_metadata":{},"id":"msg_01CaPVGfmUsXUgzxFt3SAy7i","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/metadata
data: {"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e":{"metadata":{"graph_id":"agent","run_attempt":1,"langgraph_version":"0.2.53","langgraph_plan":"developer","langgraph_host":"self-hosted","run_id":"1efad3cd-88bc-61fb-b67a-971f6b92e28b","user_id":"","thread_id":"94ca1fa9-5ec6-4195-b36b-b1ba47762593","assistant_id":"547f1faf-1f9a-4939-a920-f0f6dce76dd5","langgraph_step":7,"langgraph_node":"callModel","langgraph_triggers":["__start__:callModel"],"langgraph_path":["__pregel_pull","callModel"],"langgraph_checkpoint_ns":"callModel:80d82f42-3397-51f8-947a-90cd25a99a6e","__pregel_resuming":false,"__pregel_task_id":"80d82f42-3397-51f8-947a-90cd25a99a6e","checkpoint_ns":"callModel:80d82f42-3397-51f8-947a-90cd25a99a6e","ls_provider":"anthropic","ls_model_name":"claude-3-5-sonnet-20241022","ls_model_type":"chat","ls_temperature":1,"ls_max_tokens":2048}}}

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":""}],"additional_kwargs":{},"tool_call_chunks":[],"response_metadata":{},"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you."}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Sen"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments\n6. Or other Gmail-related tasks"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments\n6. Or other Gmail-related tasks\n\nCould you please let me know"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments\n6. Or other Gmail-related tasks\n\nCould you please let me know what specific help you need?"}],"additional_kwargs":{},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments\n6. Or other Gmail-related tasks\n\nCould you please let me know what specific help you need?"}],"additional_kwargs":{"stop_reason":"end_turn","stop_sequence":null},"response_metadata":{},"tool_call_chunks":[],"id":"run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e","usage_metadata":{"input_tokens":0,"output_tokens":127,"total_tokens":127},"tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/complete
data: [{"content":[{"index":0,"type":"text","text":"Hi! I can see this is our third greeting, but I still don't know how I can help you. For us to have a productive interaction, I'll need you to tell me what specific task you'd like to accomplish. \n\nYou can ask me to:\n1. Send an email (you'll need to provide recipient, subject, and message)\n2. Search your emails\n3. Check your Gmail labels\n4. Manage your inbox\n5. Work with email attachments\n6. Or other Gmail-related tasks\n\nCould you please let me know what specific help you need?"}],"additional_kwargs":{"id":"msg_01CaPVGfmUsXUgzxFt3SAy7i","type":"message","role":"assistant","model":"claude-3-5-sonnet-20241022","stop_reason":"end_turn","stop_sequence":null},"response_metadata":{},"tool_call_chunks":[],"id":"msg_01CaPVGfmUsXUgzxFt3SAy7i","usage_metadata":{"input_tokens":4212,"output_tokens":128,"total_tokens":4340},"tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

with:

  const model = new ChatOpenAI({
    model: "gpt-4o",
  }).bindTools(tools);
curl 'http://localhost:58315/threads/cac75040-e757-4d75-a6ef-8e9f98821255/runs/stream' \
  -H 'Accept: */*' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'DNT: 1' \
  -H 'Origin: http://localhost:3000' \
  -H 'Pragma: no-cache' \
  -H 'Referer: http://localhost:3000/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Chromium";v="131", "Not_A Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw '{"input":{"messages":[{"type":"human","content":"hello"}]},"stream_mode":"messages","assistant_id":"547f1faf-1f9a-4939-a920-f0f6dce76dd5"}'
event: metadata
data: {"run_id":"1efad3d6-110e-6820-a32f-3478cceca7a6","attempt":1}

event: messages/complete
data: [{"content":"hi","additional_kwargs":{},"response_metadata":{},"id":"cb6bed6c-de0f-4278-9523-87a4758b74d9","type":"human"},{"content":"Hello! How can I assist you today?","additional_kwargs":{},"response_metadata":{"usage":{"prompt_tokens":1954,"completion_tokens":10,"total_tokens":1964,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}},"tool_call_chunks":[],"id":"chatcmpl-AYPzJ9NfX7w3TtQLgVhke5tBvFNU8","tool_calls":[],"invalid_tool_calls":[],"type":"ai"},{"content":"hi","additional_kwargs":{},"response_metadata":{},"id":"4f00b60f-0ad9-4c1b-8197-1ab203b995d5","type":"human"},{"content":"Hi again! How can I assist you?","additional_kwargs":{},"response_metadata":{"usage":{"prompt_tokens":1972,"completion_tokens":10,"total_tokens":1982,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}},"tool_call_chunks":[],"id":"chatcmpl-AYPzZ5CPJXxomPRbhq7LQgjUJp6eo","tool_calls":[],"invalid_tool_calls":[],"type":"ai"},{"content":"hello","additional_kwargs":{},"response_metadata":{},"id":"baa55cfc-5bdc-44d6-a374-7c8e52d6bf52","type":"human"}]

event: messages/metadata
data: {"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu":{"metadata":{"graph_id":"agent","run_attempt":1,"langgraph_version":"0.2.53","langgraph_plan":"developer","langgraph_host":"self-hosted","run_id":"1efad3d6-110e-6820-a32f-3478cceca7a6","user_id":"","thread_id":"cac75040-e757-4d75-a6ef-8e9f98821255","assistant_id":"547f1faf-1f9a-4939-a920-f0f6dce76dd5","langgraph_step":7,"langgraph_node":"callModel","langgraph_triggers":["__start__:callModel"],"langgraph_path":["__pregel_pull","callModel"],"langgraph_checkpoint_ns":"callModel:fcd17119-a648-5953-920a-f093ef5b63cd","__pregel_resuming":false,"__pregel_task_id":"fcd17119-a648-5953-920a-f093ef5b63cd","checkpoint_ns":"callModel:fcd17119-a648-5953-920a-f093ef5b63cd","ls_provider":"openai","ls_model_name":"gpt-4o","ls_model_type":"chat","ls_temperature":1}}}

event: messages/partial
data: [{"content":"","tool_call_chunks":[],"additional_kwargs":{},"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","response_metadata":{"usage":{}},"tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello!","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I help","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I help you","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I help you today","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I help you today?","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/partial
data: [{"content":"Hello! How can I help you today?","additional_kwargs":{},"response_metadata":{"usage":{}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

event: messages/complete
data: [{"content":"Hello! How can I help you today?","additional_kwargs":{},"response_metadata":{"usage":{"prompt_tokens":1990,"completion_tokens":10,"total_tokens":2000,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}}},"tool_call_chunks":[],"id":"chatcmpl-AYQ05fgVqPDqoZljIKRXVupuiVjFu","usage_metadata":{"input_tokens":1990,"output_tokens":10,"total_tokens":2000,"input_token_details":{"audio":0,"cache_read":0},"output_token_details":{"audio":0,"reasoning":0}},"tool_calls":[],"invalid_tool_calls":[],"type":"ai"}]

Please let me know if you need more additional information 🙏 Appreciate taking a look!

@Yonom
Copy link
Owner

Yonom commented Nov 28, 2024

Hey, it turns out that for anthropic, the "messages/partial" events have a different id than the final "messages/complete" event... ("run-9f1d3999-9fdc-40f0-bf37-e41dab043a8e" vs "msg_01CaPVGfmUsXUgzxFt3SAy7i")

I'll check with the LangChain team to see how to handle this

@masato-io
Copy link
Author

masato-io commented Nov 28, 2024

Gotcha, that makes sense; thank you for pinpointing the root cause and appreciate you checking with LangChain team! I'll explore if I can adjust from the LangGraph code as well. Please feel free to close this issue if you think this issue is more towards the LangChain side 👋

@masato-io
Copy link
Author

masato-io commented Nov 30, 2024

Closing as I was able to workaround it by extending Runnable (import { Runnable } from "@langchain/core/runnables";) to adjust it from the LangGraph side for now. @Yonom thank you for the input 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants