twelvelabs-io / tl-jockey

Jockey is a conversational video agent.
48 stars 10 forks source link

Error in LangGraph `ChatPromptTemplate` #73

Open seyeong-han opened 2 weeks ago

seyeong-han commented 2 weeks ago

I think LangGraph docker still not fixed. It seems like they changed the ChatPromptTemplate and I will check their update.

Reproduce The Error

python3 -m jockey server
cd frontend
yarn start

I got the error when I sent a message through the jockey chat.

Error

langgraph-api-1       | 2024-09-04T21:59:03.490294Z [error    ] Background run failed          [langgraph_api.queue] api_revision=49eef89 api_variant=licensed run_created_at=2024-09-04T21:59:03.424610+00:00 run_ended_at=2024-09-04T21:59:03.490032 run_exec_ms=58 run_id=1ef6b08e-5fcb-6c9f-822c-9faa1b062a44 run_started_at=2024-09-04T21:59:03.432027+00:00
langgraph-api-1       | Traceback (most recent call last):
langgraph-api-1       |   File "/api/langgraph_api/queue.py", line 92, in worker
langgraph-api-1       |   File "/usr/local/lib/python3.11/asyncio/tasks.py", line 489, in wait_for
langgraph-api-1       |     return fut.result()
langgraph-api-1       |            ^^^^^^^^^^^^
langgraph-api-1       |   File "/api/langgraph_api/shared/stream.py", line 225, in consume
langgraph-api-1       |   File "/api/langgraph_api/shared/stream.py", line 213, in consume
langgraph-api-1       |   File "/api/langgraph_api/shared/stream.py", line 124, in astream_state
langgraph-api-1       |   File "/api/langgraph_api/shared/asyncio.py", line 39, in wait_if_not_done
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1247, in astream_events
langgraph-api-1       |     async for event in event_stream:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/event_stream.py", line 1005, in _astream_events_implementation_v2
langgraph-api-1       |     await task
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/event_stream.py", line 965, in consume_astream
langgraph-api-1       |     async for _ in event_streamer.tap_output_aiter(run_id, stream):
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/event_stream.py", line 204, in tap_output_aiter
langgraph-api-1       |     async for chunk in output:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 1558, in astream
langgraph-api-1       |     _panic_or_proceed(all_futures, loop.step, asyncio.TimeoutError)
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 1733, in _panic_or_proceed
langgraph-api-1       |     raise exc
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/retry.py", line 76, in arun_with_retry
langgraph-api-1       |     async for _ in task.proc.astream(task.input, task.config):
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 3286, in astream
langgraph-api-1       |     async for chunk in self.atransform(input_aiter(), config, **kwargs):
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 3269, in atransform
langgraph-api-1       |     async for chunk in self._atransform_stream_with_config(
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2161, in _atransform_stream_with_config
langgraph-api-1       |     chunk: Output = await asyncio.create_task(  # type: ignore[call-arg]
langgraph-api-1       |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/event_stream.py", line 181, in tap_output_aiter
langgraph-api-1       |     first = await py_anext(output, default=sentinel)
langgraph-api-1       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/utils/aiter.py", line 78, in anext_impl
langgraph-api-1       |     return await __anext__(iterator)
langgraph-api-1       |            ^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 3239, in _atransform
langgraph-api-1       |     async for output in final_pipeline:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1314, in atransform
langgraph-api-1       |     async for ichunk in input:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1314, in atransform
langgraph-api-1       |     async for ichunk in input:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/output_parsers/transform.py", line 85, in atransform
langgraph-api-1       |     async for chunk in self._atransform_stream_with_config(
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2118, in _atransform_stream_with_config
langgraph-api-1       |     final_input: Optional[Input] = await py_anext(input_for_tracing, None)
langgraph-api-1       |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/utils/aiter.py", line 78, in anext_impl
langgraph-api-1       |     return await __anext__(iterator)
langgraph-api-1       |            ^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/utils/aiter.py", line 127, in tee_peer
langgraph-api-1       |     item = await iterator.__anext__()
langgraph-api-1       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 5311, in atransform
langgraph-api-1       |     async for item in self.bound.atransform(
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1314, in atransform
langgraph-api-1       |     async for ichunk in input:
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1332, in atransform
langgraph-api-1       |     async for output in self.astream(final, config, **kwargs):
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 875, in astream
langgraph-api-1       |     yield await self.ainvoke(input, config, **kwargs)
langgraph-api-1       |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/prompts/base.py", line 210, in ainvoke
langgraph-api-1       |     return await self._acall_with_config(
langgraph-api-1       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1835, in _acall_with_config
langgraph-api-1       |     output: Output = await asyncio.create_task(coro, context=context)  # type: ignore
langgraph-api-1       |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/prompts/base.py", line 166, in _aformat_prompt_with_error_handling
langgraph-api-1       |     _inner_input = self._validate_input(inner_input)
langgraph-api-1       |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
langgraph-api-1       |   File "/usr/local/lib/python3.11/site-packages/langchain_core/prompts/base.py", line 156, in _validate_input
langgraph-api-1       |     raise KeyError(msg)
langgraph-api-1       | KeyError: "Input to ChatPromptTemplate is missing variables {'made_plan', 'active_plan'}.  Expected: ['active_plan', 'chat_history', 'made_plan'] Received: ['chat_history']\nNote: if you intended {made_plan} to be part of the string and not a variable, please escape it with double curly braces like: '{{made_plan}}'."
ojadeyemi commented 1 week ago

Any updates @seyeong-han

I am getting the same error here. Usually, the made_plan and active_plan values are always passed in the jockey terminal. But we must figure out how to pass them from the front end to the langgraph API.

# Here the default values are always given in the terminal
jockey_input = {
    "chat_history": user_input,
    "made_plan": False,
    "next_worker": None,
    "active_plan": None
}

Without specifying these values also throws the error on langsmith debugger

seyeong-han commented 6 days ago

I found the error occurs in the def _build_supervisor from class Jockey(StateGraph) by looking at the LangGraph Debugger.

image

ojadeyemi commented 4 days ago

Also, the default values of the made plan and active plan passed alongside the user input from the frontend solves this issue.

in streameventsapi.js line 38

or your solution might work too

seyeong-han commented 3 days ago

Yes, both ways can solve the error, but given the value under the code, it looks more natural, not directly on user chat.