Skip to content

Commit 54c8ef6

Browse files
feat: add directory in agent.summarize() (#3188)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 7d4f474 commit 54c8ef6

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

camel/agents/chat_agent.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ def summarize(
10501050
self,
10511051
filename: Optional[str] = None,
10521052
summary_prompt: Optional[str] = None,
1053+
working_directory: Optional[Union[str, Path]] = None,
10531054
) -> Dict[str, Any]:
10541055
r"""Summarize the agent's current conversation context and persist it
10551056
to a markdown file.
@@ -1061,6 +1062,9 @@ def summarize(
10611062
summary_prompt (Optional[str]): Custom prompt for the summarizer.
10621063
When omitted, a default prompt highlighting key decisions,
10631064
action items, and open questions is used.
1065+
working_directory (Optional[str|Path]): Optional directory to save
1066+
the markdown summary file. If provided, overrides the default
1067+
directory used by ContextUtility.
10641068
10651069
Returns:
10661070
Dict[str, Any]: A dictionary containing the summary text, file
@@ -1075,7 +1079,12 @@ def summarize(
10751079

10761080
try:
10771081
if self._context_utility is None:
1078-
self._context_utility = ContextUtility()
1082+
if working_directory is not None:
1083+
self._context_utility = ContextUtility(
1084+
working_directory=str(working_directory)
1085+
)
1086+
else:
1087+
self._context_utility = ContextUtility()
10791088

10801089
# Get conversation directly from agent's memory
10811090
messages, _ = self.memory.get_context()
@@ -1116,12 +1125,17 @@ def summarize(
11161125
else:
11171126
self._context_summary_agent.reset()
11181127

1119-
prompt_text = summary_prompt or (
1120-
"Summarize the following conversation in concise markdown "
1121-
"bullet points highlighting key decisions, action items, and "
1122-
"open questions.\n\n"
1123-
f"{conversation_text}"
1124-
)
1128+
if summary_prompt:
1129+
prompt_text = (
1130+
f"{summary_prompt.rstrip()}\n\n"
1131+
f"Context information:\n{conversation_text}"
1132+
)
1133+
else:
1134+
prompt_text = (
1135+
"Summarize the context information in concise markdown "
1136+
"bullet points highlighting key decisions, action items.\n"
1137+
f"Context information:\n{conversation_text}"
1138+
)
11251139

11261140
try:
11271141
response = self._context_summary_agent.step(prompt_text)

0 commit comments

Comments
 (0)