Skip to content

Keep the signed-in HA user in Assist session keys - #44

Open
razshlomo wants to merge 1 commit into
techartdev:mainfrom
razshlomo:fix/assist-session-per-user
Open

razshlomo wants to merge 1 commit into
techartdev:mainfrom
razshlomo:fix/assist-session-per-user

Conversation

@razshlomo

Copy link
Copy Markdown

When Assist runs through a pipeline (phone app, satellite), Home Assistant always supplies a conversation id. _resolve_conversation_id checked that id first, so the assist_user_<id> branch was never reached and the agent cannot tell which HA user is speaking. The user id is not sent any other way.

Observed on 0.1.65 with voice_agent_id: home and no session override: a turn from the HA phone app landed in agent:home:01m4hf34nxm64w74ab60v9pbrc. The same agent called through /api/conversation/process without a conversation id landed in agent:home:assist_user_<id>.

Change: the base-id choice moves to helpers.assist_base_session_id. When both a signed-in user and a conversation id are present, the key is assist_user_<id>:<conversation>: still one session per conversation, as today, and the agent can now see the speaker. A follow-up turn that hands back a key already carrying the user is kept as is, so it is never prefixed twice. Without a user the order is unchanged (conversation id, then device, then assist_default). The "Assist session ID override" still wins when set, and agent scoping is unchanged. README: one line under "Model selection" describes the key.

Tests: added AssistBaseSessionIdTests (7 cases, including a scoped follow-up round trip); python -m unittest discover -s tests -v passes (16 tests), plus the Python syntax check and node --check from the validate workflow.

When Assist runs through a pipeline (phone app, satellite), Home Assistant always supplies a conversation id. `_resolve_conversation_id` checked that id first, so the `assist_user_<id>` branch was never reached and the agent cannot tell which HA user is speaking. The user id is not sent any other way.

Observed on 0.1.65 with `voice_agent_id: home` and no session override: a turn from the HA phone app landed in `agent:home:01m4hf34nxm64w74ab60v9pbrc`. The same agent called through `/api/conversation/process` without a conversation id landed in `agent:home:assist_user_<id>`.

Change: the base-id choice moves to `helpers.assist_base_session_id`. When both a signed-in user and a conversation id are present, the key is `assist_user_<id>:<conversation>`: still one session per conversation, as today, and the agent can now see the speaker. A follow-up turn that hands back a key already carrying the user is kept as is, so it is never prefixed twice. Without a user the order is unchanged (conversation id, then device, then `assist_default`). The "Assist session ID override" still wins when set, and agent scoping is unchanged. README: one line under "Model selection" describes the key.

Tests: added `AssistBaseSessionIdTests` (7 cases, including a scoped follow-up round trip); `python -m unittest discover -s tests -v` passes (16 tests), plus the Python syntax check and `node --check` from the validate workflow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant