Session ID Error When Using Agent Within a Sub Flow
Bug Description
Description
When creating a “Sub Flow” component that references a flow containing an Agent, an error is repeatedly thrown:
"It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields."
Despite investigating the source code, I haven’t yet located the exact cause or solution.
Steps to Reproduce
- Create the first flow (e.g., “Main Flow”) with the following structure:
- Chat Message → Sub Flow
- The Sub Flow points to the second flow.
- Chat Message → Sub Flow
- Create the second flow (e.g., “Basic Agent Flow”) with:
- Chat Message (input) → Agent (input)
- Calculator (Tool) → Agent (tool)
- The output goes back to Chat Message.
- Send a message in the first flow (e.g., “2x2”).
Basic Agent Flow.json Main Flow.json
Expected Result
The flow should process the conversation seamlessly, including the Agent’s response from the sub flow.
Actual Result
The conversation fails with:
"It looks like we're missing some important information: session_id (unique conversation identifier)..."
Full stack trace
Error building Component Sub Flow:
Error running graph: Error building Component Agent:
It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields.
Traceback (most recent call last):
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 837, in build_results
return await self._build_with_tracing()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 819, in _build_with_tracing
_results, _artifacts = await self._build_results()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 883, in _build_results
result = await method()
File "<string>", line 88, in message_response
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/base/agents/agent.py", line 158, in run_agent
result = await process_agent_events(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/base/agents/events.py", line 253, in process_agent_events
agent_message = await asyncio.to_thread(send_message_method, message=agent_message)
File "/Users/jasonmelman/.pyenv/versions/3.10.14/lib/python3.10/asyncio/threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
File "/Users/jasonmelman/.pyenv/versions/3.10.14/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 1009, in send_message
stored_message = self._store_message(message)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 1034, in _store_message
messages = store_message(message, flow_id=flow_id)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/memory.py", line 179, in store_message
raise ValueError(msg)
ValueError: It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 709, in _build_results
result = await initialize.loading.get_instance_results(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/interface/initialize/loading.py", line 68, in get_instance_results
return await build_component(params=custom_params, custom_component=custom_component)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/interface/initialize/loading.py", line 145, in build_component
build_results, artifacts = await custom_component.build_results()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 848, in build_results
self.send_error(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 1135, in send_error
self.send_message(error_message)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 1009, in send_message
stored_message = self._store_message(message)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 1034, in _store_message
messages = store_message(message, flow_id=flow_id)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/memory.py", line 179, in store_message
raise ValueError(msg)
ValueError: It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 771, in _run
await self.process(start_component_id=start_component_id, fallback_to_env_vars=fallback_to_env_vars)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 1518, in process
next_runnable_vertices = await self._execute_tasks(tasks, lock=lock)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 1570, in _execute_tasks
raise result
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 1419, in build_vertex
await vertex.build(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 819, in build
await step(user_id=user_id, event_manager=event_manager, **kwargs)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 497, in _build
await self._build_results(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 724, in _build_results
raise ComponentBuildError(msg, tb) from exc
langflow.exceptions.component.ComponentBuildError: Error building Component Agent:
It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/vertex/base.py", line 709, in _build_results
result = await initialize.loading.get_instance_results(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/interface/initialize/loading.py", line 68, in get_instance_results
return await build_component(params=custom_params, custom_component=custom_component)
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/interface/initialize/loading.py", line 145, in build_component
build_results, artifacts = await custom_component.build_results()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 837, in build_results
return await self._build_with_tracing()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 819, in _build_with_tracing
_results, _artifacts = await self._build_results()
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/component.py", line 883, in _build_results
result = await method()
File "<string>", line 100, in generate_results
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/custom/custom_component/custom_component.py", line 490, in run_flow
return await run_flow(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/helpers/flow.py", line 123, in run_flow
return await graph.arun(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 840, in arun
run_outputs = await self._run(
File "/Users/jasonmelman/dev/langflow_testing/.venv/lib/python3.10/site-packages/langflow/graph/graph/base.py", line 776, in _run
raise ValueError(msg) from exc
ValueError: Error running graph: Error building Component Agent:
It looks like we're missing some important information: session_id (unique conversation identifier). Please ensure that your message includes all the required fields.
Reproduction
- Create the first flow (e.g., “Main Flow”) with the following structure:
- Chat Message → Sub Flow
- The Sub Flow points to the second flow.
- Chat Message → Sub Flow
- Create the second flow (e.g., “Basic Agent Flow”) with:
- Chat Message (input) → Agent (input)
- Calculator (Tool) → Agent (tool)
- The output goes back to Chat Message.
- Send a message in the "Main Flow" (e.g., “2x2+3”).
Expected behavior
The flow should process the conversation seamlessly, including the Agent’s response from the sub flow.
Who can help?
No response
Operating System
MacOS Sequoia 15.1.1 (24B91)
Langflow Version
1.1.1
Python Version
3.10
Screenshot
No response
Flow File
Hello, @jmelm93! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together! 😄
To resolve the "session_id (unique conversation identifier) missing" error when using an Agent within a Sub Flow in Langflow, ensure that the session_id is properly set in your agent's context. The session_id is typically retrieved from either self.graph.session_id or self._session_id. If neither is available, session_id will be None, which could lead to the error.
Here's what you can do:
-
Check if
self.graphis properly initialized: Ensure thatself.graphis set and has asession_idattribute before running the agent. -
Set
_session_idifself.graphis not used: Ifself.graphis not used or does not have asession_id, make sure to setself._session_idwith a unique identifier before running the agent. -
Debugging: Add debugging statements to check if
self.graphandself._session_idare set correctly before the agent is executed.
Example code to ensure session_id is set:
if hasattr(self, "graph") and hasattr(self.graph, "session_id"):
session_id = self.graph.session_id
elif hasattr(self, "_session_id"):
session_id = self._session_id
else:
# Set a default session_id or raise an error
session_id = "default_session_id" # or raise an error
Ensure that the session_id is correctly set in your flow to avoid the error [1].
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
The above bot answer does not resolve the problem. When logging self.graph.session_id within the "Sub Flow" component, the session_id is present, as shown in the log output below:
Log output:
2024-12-24 15:42:10 - INFO - <string>:92 <string> - self.graph.session_id: f053ea08-de8c-4844-a24e-fe5d0fcaaf80
However, this context does not appear to propagate to the components being built by the "Sub Flow." This seems to be an issue with the default behavior of the out-of-the-box "Sub Flow" component.
having the same issue. any solution?
No, I’ve kind of given up on this after trying to resolve it for several days. Hopefully, this issue will get a response at some point down the line.
Hi @Amakua and @jmelm93
Thank you for your feedback. We are currently developing a new component called RunFlow, which will function similarly to both Sub Flow and Flow as Tool.
Please test your use case with the new component.
Here is the PR: https://github.com/langflow-ai/langflow/pull/5518.
If you continue to experience issues after testing, please reopen this issue. I look forward to hearing your feedback.