Represents a response from an LLM.
| 156 | |
| 157 | @dataclass |
| 158 | class LLMResponse: |
| 159 | """Represents a response from an LLM.""" |
| 160 | content: str |
| 161 | tool_calls: list[ToolCall] = field(default_factory=list) |
| 162 | stop_reason: StopReason = StopReason.END_TURN |
| 163 | model: str = '' |
| 164 | usage: Usage = field(default_factory=Usage) |
| 165 | raw_response: Optional[Any] = None |
| 166 | |
| 167 | @property |
| 168 | def has_tool_calls(self) -> bool: |
| 169 | """Check if the response contains tool calls.""" |
| 170 | return len(self.tool_calls) > 0 |
| 171 | |
| 172 | def to_message(self) -> Message: |
| 173 | """Convert response to an assistant message.""" |
| 174 | return Message.assistant( |
| 175 | content=self.content, |
| 176 | tool_calls=self.tool_calls |
| 177 | ) |
| 178 | |
| 179 | def to_dict(self) -> dict: |
| 180 | """Convert to dictionary representation.""" |
| 181 | return { |
| 182 | 'content': self.content, |
| 183 | 'tool_calls': [tc.to_dict() for tc in self.tool_calls], |
| 184 | 'stop_reason': self.stop_reason.value, |
| 185 | 'model': self.model, |
| 186 | 'usage': self.usage.to_dict() |
| 187 | } |
| 188 | |
| 189 | |
| 190 | @dataclass |
no outgoing calls
no test coverage detected