Skip to content

Feature request: session updateState should patch the state instead of replace #1437

@pavelgj

Description

@pavelgj

Description

Currently there's inconsistent behavior when using updateState(). When updating a single property, it appears to replace the entire state object rather than patching it:

console.log(session.state) 
// { userName: 'God', colour: 'Green' }

async (input) => {
  ai.currentSession().updateState({ 
    colour: input.colour,
  });
  return `colour updated to ${input.colour}`;
}

console.log(session.state)
// { colour: 'Green' }  // userName was cleared

The current workaround is to manually spread the existing state:

async (input) => {
  ai.currentSession().updateState({
    ...ai.currentSession().state,
    userName: input.userName,
  });
}

It should be changed to patch

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions