{"record":{"id":"eff0d58d946424de","repo":"run-llama/llama_index","slug":"must-provide-either-user-msg-or-chat-history-eff0d5","errorCode":null,"errorMessage":"Must provide either user_msg or chat_history","messagePattern":"Must provide either user_msg or chat_history","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/agent/workflow/multi_agent_workflow.py","lineNumber":427,"sourceCode":"            )\n            await ctx.store.set(\"user_msg_str\", content_str)\n        elif chat_history and not all(\n            message.role == \"system\" for message in chat_history\n        ):\n            # If no user message, use the last message from chat history as user_msg_str\n            user_hist: List[ChatMessage] = [\n                msg for msg in chat_history if msg.role == \"user\"\n            ]\n            content_str = \"\\n\".join(\n                [\n                    block.text\n                    for block in user_hist[-1].blocks\n                    if isinstance(block, TextBlock)\n                ]\n            )\n            await ctx.store.set(\"user_msg_str\", content_str)\n        else:\n            raise ValueError(\"Must provide either user_msg or chat_history\")\n\n        # Get all messages from memory\n        input_messages = await memory.aget()\n\n        # send to the current agent\n        current_agent_name: str = await ctx.store.get(\"current_agent_name\")\n        return AgentInput(input=input_messages, current_agent_name=current_agent_name)\n\n    @step\n    async def setup_agent(self, ctx: Context, ev: AgentInput) -> AgentSetup:\n        \"\"\"Main agent handling logic.\"\"\"\n        current_agent_name = ev.current_agent_name\n        agent = self.agents[current_agent_name]\n        llm_input = [*ev.input]\n\n        if agent.system_prompt:\n            llm_input = [\n                ChatMessage(role=\"system\", content=agent.system_prompt),","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/agent/workflow/multi_agent_workflow.py#L409-L445","documentation":"AgentWorkflow's init step requires input: user_msg (str or List[ChatMessage]) or a chat_history (List[ChatMessage]). If neither is passed to .run()/.astream(), there is no user turn to process and the workflow raises before any agent runs.","triggerScenarios":"Calling `await wf.run()` with no arguments; passing only memory= (ChatMemoryBuffer) without chat_history; passing an empty chat_history list — an empty list is falsy and falls into the same else branch.","commonSituations":"Expecting AgentWorkflow to continue from memory alone (memory is loaded after this check, but the input check comes first); refactoring run() calls and dropping the message argument; passing an empty list after filtering chat history.","solutions":["Pass a message: `await wf.run(user_msg=\"Summarize this\", memory=memory)`.","Or pass chat_history=[ChatMessage(role=\"user\", content=\"...\")] together with memory.","If resuming a conversation from memory, still supply at least the new user turn via user_msg."],"exampleFix":"# before\nresp = await wf.run(memory=memory)  # ValueError\n\n# after\nresp = await wf.run(user_msg=\"What did we discuss?\", memory=memory)","handlingStrategy":"validation","validationCode":"def validate_run_input(user_msg=None, chat_history=None):\n    if not user_msg and not chat_history:\n        raise ValueError(\"AgentWorkflow.run requires user_msg or non-empty chat_history\")","typeGuard":"def has_run_input(user_msg, chat_history) -> bool:\n    return bool(user_msg) or bool(chat_history)","tryCatchPattern":null,"preventionTips":["Always pass user_msg for each user turn, even when memory carries prior context.","Remember an empty chat_history list is treated as absent.","Wrap wf.run calls in a small helper that enforces the input contract."],"tags":["agent-workflow","validation","input","runtime"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}