Skip to content

Commit 2855c3b

Browse files
authored
Merge pull request #665 from dataelement/fix/agentbay-browser-extract-pydantic-schema
fix(agentbay): use Pydantic RootModel[Any] for browser extract schema
2 parents 5aef9da + 3963fe5 commit 2855c3b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

backend/app/services/agentbay_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
import uuid
99
from dataclasses import dataclass
1010
from datetime import datetime, timedelta
11-
from typing import Optional
11+
from typing import Any, Optional
1212
from loguru import logger
13+
from pydantic import RootModel
14+
15+
16+
class GenericExtractSchema(RootModel[Any]):
17+
pass
18+
1319

1420
from agentbay import AgentBay, CreateSessionParams
1521
from app.core.logging_config import _disable_agentbay_logger_override, configure_logging
@@ -268,15 +274,18 @@ async def browser_extract(self, instruction: str, selector: str = "") -> dict:
268274
await asyncio.sleep(3)
269275

270276
from agentbay._common.models.browser_operator import ExtractOptions
271-
# Use a generic dict schema since we cannot define a Pydantic model at runtime
277+
# Use a generic RootModel schema since we cannot define a custom Pydantic model at runtime
272278
options = ExtractOptions(
273279
instruction=instruction,
274-
schema=dict,
280+
schema=GenericExtractSchema,
275281
selector=selector or None,
276282
)
277283
success, data = await asyncio.to_thread(
278284
self._session.browser.operator.extract, options
279285
)
286+
if success and data:
287+
if hasattr(data, "model_dump"):
288+
data = data.model_dump()
280289
return {"success": success, "data": data}
281290

282291
async def browser_observe(self, instruction: str, selector: str = "") -> dict:

0 commit comments

Comments
 (0)