def test_qp_agent_stateful_fn() -> None:
    """
    Test query pipeline agent with stateful components.

    The old flows of using `AgentInputComponent` and `AgentFnComponent` are deprecated.

    """
    agent_input = StatefulFnComponent(fn=mock_agent_input_fn_stateful)
    fn_component = FnComponent(fn=mock_fn)
    agent_output = StatefulFnComponent(fn=mock_agent_output_fn_stateful)
    qp = QueryPipeline(chain=[agent_input, fn_component, agent_output])

    agent_worker = QueryPipelineAgentWorker(pipeline=qp)
    agent_runner = AgentRunner(agent_worker=agent_worker)

    # test create_task
    task = agent_runner.create_task("foo")
    assert task.input == "foo"

    step_output = agent_runner.run_step(task.task_id)
    assert str(step_output.output) == "foo3"
    assert step_output.is_last is False

    step_output = agent_runner.run_step(task.task_id)
    assert str(step_output.output) == "foo33"
    assert step_output.is_last is True

    Test query pipeline agent with stateful components.

    The old flows of using `AgentInputComponent` and `AgentFnComponent` are deprecated.

    
llama-index-core/tests/agent/custom/test_query_pipeline.py