Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
add error_code_mapping and extracted_information_schema to task v2 (#1950)
Shuchang Zheng39162ded9b7e
diff --git a/alembic/versions/2025_03_18_1850-c6c0eee7f88d_add_error_code_mapping_and_extracted_.py b/alembic/versions/2025_03_18_1850-c6c0eee7f88d_add_error_code_mapping_and_extracted_.pynew file mode 100644index 000000000..f8aa5dd63--- /dev/null+++ b/alembic/versions/2025_03_18_1850-c6c0eee7f88d_add_error_code_mapping_and_extracted_.py@@ -0,0 +1,33 @@+"""add error_code_mapping and extracted_information_schema to task v2++Revision ID: c6c0eee7f88d+Revises: 268dcc995513+Create Date: 2025-03-18 18:50:28.930836+00:00++"""++from typing import Sequence, Union++import sqlalchemy as sa++from alembic import op++# revision identifiers, used by Alembic.+revision: str = "c6c0eee7f88d"+down_revision: Union[str, None] = "268dcc995513"+branch_labels: Union[str, Sequence[str], None] = None+depends_on: Union[str, Sequence[str], None] = None+++def upgrade() -> None:+ # ### commands auto generated by Alembic - please adjust! ###+ op.add_column("observer_cruises", sa.Column("extracted_information_schema", sa.JSON(), nullable=True))+ op.add_column("observer_cruises", sa.Column("error_code_mapping", sa.JSON(), nullable=True))+ # ### end Alembic commands ###+++def downgrade() -> None:+ # ### commands auto generated by Alembic - please adjust! ###+ op.drop_column("observer_cruises", "error_code_mapping")+ op.drop_column("observer_cruises", "extracted_information_schema")+ # ### end Alembic commands ###diff --git a/skyvern/forge/prompts/skyvern/task_v2_summary.j2 b/skyvern/forge/prompts/skyvern/task_v2_summary.j2index 5c71f447d..4b54e7c2b 100644--- a/skyvern/forge/prompts/skyvern/task_v2_summary.j2+++ b/skyvern/forge/prompts/skyvern/task_v2_summary.j2@@ -5,13 +5,15 @@ You want to present the response in a clear way so that user can clearly understReply in JSON format with the following keys:{"description": str, // Summarize what has been achieved and describe the information extracted related to the user goal if any. Be precise and concise.- "output": json, // Structured data related to the user goal if any.+ "output": json, // Structured data related to the user goal if any.{% if extracted_information_schema %} Use the data schema for the output field.{% endif %}}User goal:```{{ user_goal }}-```+```{% if extracted_information_schema %}++The ideal schema for the "output" field: {{ extracted_information_schema }}{% endif %}Task history (the earliest task is the first in the list and the latest is the last in the list):```diff --git a/skyvern/forge/sdk/db/models.py b/skyvern/forge/sdk/db/models.pyindex 1611d02fa..c401f21d4 100644--- a/skyvern/forge/sdk/db/models.py+++ b/skyvern/forge/sdk/db/models.py@@ -588,6 +588,8 @@ class TaskV2Model(Base):totp_verification_url = Column(String, nullable=True)totp_identifier = Column(String, nullable=True)proxy_location = Column(String, nullable=True)+ extracted_information_schema = Column(JSON, nullable=True)+ error_code_mapping = Column(JSON, nullable=True)created_at = Column(DateTime, default=datetime.datetime.utcnow, nullable=False)modified_at = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow, nullable=False)diff --git a/skyvern/forge/sdk/schemas/task_v2.py b/skyvern/forge/sdk/schemas/task_v2.pyindex 3839062ff..cfc00a66a 100644--- a/skyvern/forge/sdk/schemas/task_v2.py+++ b/skyvern/forge/sdk/schemas/task_v2.py@@ -41,6 +41,8 @@ class TaskV2(BaseModel):totp_identifier: str | None = Noneproxy_location: ProxyLocation | None = Nonewebhook_callback_url: str | None = None+ extracted_information_schema: dict | list | str | None = None+ error_code_mapping: dict | None = Nonecreated_at: datetimemodified_at: datetime@@ -117,6 +119,8 @@ class TaskV2Request(BaseModel):totp_identifier: str | None = Noneproxy_location: ProxyLocation | None = Nonepublish_workflow: bool = False+ extracted_information_schema: dict | list | str | None = None+ error_code_mapping: dict[str, str] | None = None@field_validator("url", "webhook_callback_url", "totp_verification_url")@classmethoddiff --git a/skyvern/forge/sdk/services/task_v2_service.py b/skyvern/forge/sdk/services/task_v2_service.pyindex 78dc1ecde..cf008e495 100644--- a/skyvern/forge/sdk/services/task_v2_service.py+++ b/skyvern/forge/sdk/services/task_v2_service.py@@ -1395,6 +1395,7 @@ async def _summarize_task_v2("task_v2_summary",user_goal=task_v2.prompt,task_history=task_history,+ extracted_information_schema=task_v2.extracted_information_schema,local_datetime=datetime.now(context.tz_info).isoformat(),)task_v2_summary_resp = await app.LLM_API_HANDLER(