How to get full chat context including initial history in custom nodes

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

How do I get session/agent history properly in STT/TTS modules?

When initializing the agent, I provided a history chat_ctx of 13 items using Agent(chat_ctx=[...]). In STT, I use:

session = get_job_context()._primary_agent_session
items = session.history.items

However, items size starts from 1, missing the chat_ctx I provided.

session.history.items only contains the chat since the agent was initialized.

To get the full context including the initial chat_ctx, use:

session.current_agent.chat_ctx.items

This should give you the full context.