(
self,
prompt: str,
matched_commands: tuple[str, ...] = (),
matched_tools: tuple[str, ...] = (),
denied_tools: tuple[PermissionDenial, ...] = (),
)
| 59 | ) |
| 60 | |
| 61 | def submit_message( |
| 62 | self, |
| 63 | prompt: str, |
| 64 | matched_commands: tuple[str, ...] = (), |
| 65 | matched_tools: tuple[str, ...] = (), |
| 66 | denied_tools: tuple[PermissionDenial, ...] = (), |
| 67 | ) -> TurnResult: |
| 68 | if len(self.mutable_messages) >= self.config.max_turns: |
| 69 | output = f'Max turns reached before processing prompt: {prompt}' |
| 70 | return TurnResult( |
| 71 | prompt=prompt, |
| 72 | output=output, |
| 73 | matched_commands=matched_commands, |
| 74 | matched_tools=matched_tools, |
| 75 | permission_denials=denied_tools, |
| 76 | usage=self.total_usage, |
| 77 | stop_reason='max_turns_reached', |
| 78 | ) |
| 79 | |
| 80 | summary_lines = [ |
| 81 | f'Prompt: {prompt}', |
| 82 | f'Matched commands: {", ".join(matched_commands) if matched_commands else "none"}', |
| 83 | f'Matched tools: {", ".join(matched_tools) if matched_tools else "none"}', |
| 84 | f'Permission denials: {len(denied_tools)}', |
| 85 | ] |
| 86 | output = self._format_output(summary_lines) |
| 87 | projected_usage = self.total_usage.add_turn(prompt, output) |
| 88 | stop_reason = 'completed' |
| 89 | if projected_usage.input_tokens + projected_usage.output_tokens > self.config.max_budget_tokens: |
| 90 | stop_reason = 'max_budget_reached' |
| 91 | self.mutable_messages.append(prompt) |
| 92 | self.transcript_store.append(prompt) |
| 93 | self.permission_denials.extend(denied_tools) |
| 94 | self.total_usage = projected_usage |
| 95 | self.compact_messages_if_needed() |
| 96 | return TurnResult( |
| 97 | prompt=prompt, |
| 98 | output=output, |
| 99 | matched_commands=matched_commands, |
| 100 | matched_tools=matched_tools, |
| 101 | permission_denials=denied_tools, |
| 102 | usage=self.total_usage, |
| 103 | stop_reason=stop_reason, |
| 104 | ) |
| 105 | |
| 106 | def stream_submit_message( |
| 107 | self, |
no test coverage detected