Skip to content

Commit 015071c

Browse files
feat: add custom guidance to summarize_when_long hook (#261)
* feat: add custom guidance to summarize_when_long hook * fix: linting errors
1 parent f0aab19 commit 015071c

2 files changed

Lines changed: 2603 additions & 2615 deletions

File tree

dreadnode/agent/hooks/summarize.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def summarize_when_long(
4949
model: str | rg.Generator | None = None,
5050
max_tokens: int = 100_000,
5151
min_messages_to_keep: int = 5,
52+
guidance: str = "",
5253
) -> "Hook":
5354
"""
5455
Creates a hook to manage the agent's context window by summarizing the conversation history.
@@ -64,6 +65,7 @@ def summarize_when_long(
6465
max_tokens: The maximum number of tokens allowed in the context window before summarization is triggered
6566
(default is None, meaning no proactive summarization).
6667
min_messages_to_keep: The minimum number of messages to retain after summarization (default is 5).
68+
guidance: Additional guidance for the summarization process (default is "").
6769
"""
6870

6971
if min_messages_to_keep < 2:
@@ -85,6 +87,10 @@ async def summarize_when_long( # noqa: PLR0912
8587
min_messages_to_keep: int = Config(
8688
5, help="Minimum number of messages to retain after summarization"
8789
),
90+
guidance: str = Config(
91+
guidance,
92+
help="Additional guidance for the summarization process",
93+
),
8894
) -> Reaction | None:
8995
should_summarize = False
9096

@@ -149,7 +155,7 @@ async def summarize_when_long( # noqa: PLR0912
149155

150156
# Generate the summary and rebuild the messages
151157
summary = await summarize_conversation.bind(summarizer_model)(
152-
"\n".join(str(msg) for msg in messages_to_summarize)
158+
"\n".join(str(msg) for msg in messages_to_summarize), guidance=guidance
153159
)
154160
summary_content = (
155161
f"<conversation-summary messages={len(messages_to_summarize)}>\n"

0 commit comments

Comments
 (0)