Skip to content

Commit 9b8f8e2

Browse files
authored
Python: Correct chat completion agent history truncation samples (#12474)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> While addressing the developer in this [discussion](#12450), I notice that there are a few changes needed to the improve the truncation history reducer samples of the chat completion agent. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Update the samples. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent ef912a9 commit 9b8f8e2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

python/samples/concepts/agents/chat_completion_agent/chat_completion_agent_truncate_history_reducer_agent_chat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ async def main():
3939
reducer_msg_count = 10
4040
reducer_threshold = 10
4141

42-
# Create a summarization reducer and clear its history
43-
history_truncatation_reducer = ChatHistoryTruncationReducer(
42+
# Create a truncation reducer and clear its history
43+
history_truncation_reducer = ChatHistoryTruncationReducer(
4444
target_count=reducer_msg_count, threshold_count=reducer_threshold
4545
)
46-
history_truncatation_reducer.clear()
46+
history_truncation_reducer.clear()
4747

4848
# Create our agent
4949
agent = ChatCompletionAgent(
@@ -53,7 +53,7 @@ async def main():
5353
)
5454

5555
# Create a group chat using the reducer
56-
chat = AgentGroupChat(chat_history=history_truncatation_reducer)
56+
chat = AgentGroupChat(chat_history=history_truncation_reducer)
5757

5858
# Simulate user messages
5959
message_count = 50 # Number of messages to simulate
@@ -65,7 +65,7 @@ async def main():
6565
# Attempt to reduce history
6666
is_reduced = await chat.reduce_history()
6767
if is_reduced:
68-
print(f"@ History reduced to {len(history_truncatation_reducer.messages)} messages.")
68+
print(f"@ History reduced to {len(history_truncation_reducer.messages)} messages.")
6969

7070
# Invoke the agent and display responses
7171
async for message in chat.invoke(agent):

python/samples/concepts/agents/chat_completion_agent/chat_completion_agent_truncate_history_reducer_single_agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ async def main():
2828
reducer_msg_count = 10
2929
reducer_threshold = 10
3030

31-
# Create a summarization reducer
31+
# Create a truncation reducer
3232
history_truncation_reducer = ChatHistoryTruncationReducer(
33-
service=AzureChatCompletion(), target_count=reducer_msg_count, threshold_count=reducer_threshold
33+
target_count=reducer_msg_count,
34+
threshold_count=reducer_threshold,
3435
)
3536

3637
thread: ChatHistoryAgentThread = ChatHistoryAgentThread(chat_history=history_truncation_reducer)

0 commit comments

Comments
 (0)