compact method

Future<void> compact(
  1. String summary
)

Compact conversation (replace old messages with summary).

Implementation

Future<void> compact(String summary) async {
  _setState(ConversationState.compacting);
  _messages.clear();
  _messages.add({
    'role': 'user',
    'content': [
      {
        'type': 'text',
        'text':
            '[Conversation compacted. Summary of previous context:]\n\n$summary',
      },
    ],
  });
  _messages.add({
    'role': 'assistant',
    'content': [
      {
        'type': 'text',
        'text':
            'I understand. I have the context from the conversation summary. How can I continue helping you?',
      },
    ],
  });
  _setState(ConversationState.idle);
}