Example 1: Everything fits: unchanged
Input: messages = [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Paris"}}'}, {'role': 'tool', 'content': '18C, light rain'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
max_tokens = 1000
Output: [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Paris"}}'}, {'role': 'tool', 'content': '18C, light rain'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
Example 2: Oldest call and its result are dropped together
Input: messages = [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Paris"}}'}, {'role': 'tool', 'content': '18C, light rain'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
max_tokens = 52
Output: [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
Example 3: A group that doesn't fit is dropped whole, never split
Input: messages = [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Paris"}}'}, {'role': 'tool', 'content': '18C, light rain'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
max_tokens = 40
Output: [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
Example 4: Budget smaller than the pinned messages
Input: messages = [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Paris"}}'}, {'role': 'tool', 'content': '18C, light rain'}, {'role': 'assistant', 'content': '{"tool": "get_weather", "arguments": {"city": "Tokyo"}}'}, {'role': 'tool', 'content': '24C, clear'}, {'role': 'assistant', 'content': 'Paris is rainy and Tokyo is clear.'}, {'role': 'user', 'content': 'And Lima?'}]
max_tokens = 5
Output: [{'role': 'system', 'content': 'You are a helpful travel agent.'}, {'role': 'user', 'content': 'Compare the weather in Paris and Tokyo for my trip.'}]