|
27 | 27 | ) |
28 | 28 | from openhands.sdk.conversation.secret_registry import SecretValue |
29 | 29 | from openhands.sdk.conversation.state import ConversationExecutionStatus |
| 30 | +from openhands.sdk.conversation.title_utils import generate_conversation_title |
30 | 31 | from openhands.sdk.conversation.types import ( |
31 | 32 | ConversationCallbackType, |
32 | 33 | ConversationID, |
@@ -1263,29 +1264,21 @@ def generate_title(self, llm: LLM | None = None, max_length: int = 50) -> str: |
1263 | 1264 | """Generate a title for the conversation based on the first user message. |
1264 | 1265 |
|
1265 | 1266 | Args: |
1266 | | - llm: Optional LLM to use for title generation. If provided, its usage_id |
1267 | | - will be sent to the server. If not provided, uses the agent's LLM. |
| 1267 | + llm: Optional LLM to use for title generation. If not provided, |
| 1268 | + uses the agent's LLM. |
1268 | 1269 | max_length: Maximum length of the generated title. |
1269 | 1270 |
|
1270 | 1271 | Returns: |
1271 | 1272 | A generated title for the conversation. |
1272 | 1273 | """ |
1273 | | - # For remote conversations, delegate to the server endpoint |
1274 | | - payload = { |
1275 | | - "max_length": max_length, |
1276 | | - "llm": llm.model_dump(mode="json", context={"expose_secrets": True}) |
1277 | | - if llm |
1278 | | - else None, |
1279 | | - } |
| 1274 | + # Reconcile before reading state so recently posted user messages are |
| 1275 | + # visible even if they arrived between the last sync and this call. |
| 1276 | + self._state.events.reconcile() |
1280 | 1277 |
|
1281 | | - resp = _send_request( |
1282 | | - self._client, |
1283 | | - "POST", |
1284 | | - f"{self._conversation_action_base_path}/{self._id}/generate_title", |
1285 | | - json=payload, |
| 1278 | + effective_llm = llm if llm is not None else self.agent.llm |
| 1279 | + return generate_conversation_title( |
| 1280 | + events=self._state.events, llm=effective_llm, max_length=max_length |
1286 | 1281 | ) |
1287 | | - data = resp.json() |
1288 | | - return data["title"] |
1289 | 1282 |
|
1290 | 1283 | def condense(self) -> None: |
1291 | 1284 | """Force condensation of the conversation history. |
|
0 commit comments