Create summary for one execution round Args: messages: List of messages to summarize round_num: Round number Returns: Summary text
(self, messages: list[Message], round_num: int)
| 260 | print(f"{Colors.DIM} Note: API token count will update on next LLM call{Colors.RESET}") |
| 261 | |
| 262 | async def _create_summary(self, messages: list[Message], round_num: int) -> str: |
| 263 | """Create summary for one execution round |
| 264 | |
| 265 | Args: |
| 266 | messages: List of messages to summarize |
| 267 | round_num: Round number |
| 268 | |
| 269 | Returns: |
| 270 | Summary text |
| 271 | """ |
| 272 | if not messages: |
| 273 | return "" |
| 274 | |
| 275 | # Build summary content |
| 276 | summary_content = f"Round {round_num} execution process:\n\n" |
| 277 | for msg in messages: |
| 278 | if msg.role == "assistant": |
| 279 | content_text = msg.content if isinstance(msg.content, str) else str(msg.content) |
| 280 | summary_content += f"Assistant: {content_text}\n" |
| 281 | if msg.tool_calls: |
| 282 | tool_names = [tc.function.name for tc in msg.tool_calls] |
| 283 | summary_content += f" → Called tools: {', '.join(tool_names)}\n" |
| 284 | elif msg.role == "tool": |
| 285 | result_preview = msg.content if isinstance(msg.content, str) else str(msg.content) |
| 286 | summary_content += f" ← Tool returned: {result_preview}...\n" |
| 287 | |
| 288 | # Call LLM to generate concise summary |
| 289 | try: |
| 290 | summary_prompt = f"""Please provide a concise summary of the following Agent execution process: |
| 291 | |
| 292 | {summary_content} |
| 293 | |
| 294 | Requirements: |
| 295 | 1. Focus on what tasks were completed and which tools were called |
| 296 | 2. Keep key execution results and important findings |
| 297 | 3. Be concise and clear, within 1000 words |
| 298 | 4. Use English |
| 299 | 5. Do not include "user" related content, only summarize the Agent's execution process""" |
| 300 | |
| 301 | summary_msg = Message(role="user", content=summary_prompt) |
| 302 | response = await self.llm.generate( |
| 303 | messages=[ |
| 304 | Message( |
| 305 | role="system", |
| 306 | content="You are an assistant skilled at summarizing Agent execution processes.", |
| 307 | ), |
| 308 | summary_msg, |
| 309 | ] |
| 310 | ) |
| 311 | |
| 312 | summary_text = response.content |
| 313 | print(f"{Colors.BRIGHT_GREEN}✓ Summary for round {round_num} generated successfully{Colors.RESET}") |
| 314 | return summary_text |
| 315 | |
| 316 | except Exception as e: |
| 317 | print(f"{Colors.BRIGHT_RED}✗ Summary generation failed for round {round_num}: {e}{Colors.RESET}") |
| 318 | # Use simple text summary on failure |
| 319 | return summary_content |
no test coverage detected