Add organization_name and workflow_permanent_id to skyvern context, pass workflow_permanet_id when deciding which identifier to use with which llm (#2245)

This commit is contained in:
Shuchang Zheng
2025-04-29 03:55:52 +08:00
committed by GitHub
parent 7783bb0327
commit 2f10e3c430
11 changed files with 29 additions and 20 deletions

View File

@@ -2657,7 +2657,7 @@ class ForgeAgent:
)
data_extraction_summary_resp = await app.SECONDARY_LLM_API_HANDLER(
prompt=prompt, step=step, screenshots=scraped_page.screenshots, prompt_name="data-extraction-summary"
prompt=prompt, step=step, prompt_name="data-extraction-summary"
)
return ExtractAction(
reasoning=data_extraction_summary_resp.get("summary", "Extracting information from the page"),

View File

@@ -9,8 +9,10 @@ from playwright.async_api import Frame
class SkyvernContext:
request_id: str | None = None
organization_id: str | None = None
organization_name: str | None = None
task_id: str | None = None
workflow_id: str | None = None
workflow_permanent_id: str | None = None
workflow_run_id: str | None = None
task_v2_id: str | None = None
max_steps_override: int | None = None

View File

@@ -7,6 +7,7 @@ from skyvern.exceptions import OrganizationNotFound
from skyvern.forge import app
from skyvern.forge.sdk.core import skyvern_context
from skyvern.forge.sdk.core.skyvern_context import SkyvernContext
from skyvern.forge.sdk.schemas.organizations import Organization
from skyvern.forge.sdk.schemas.task_v2 import TaskV2Status
from skyvern.forge.sdk.schemas.tasks import TaskStatus
from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus
@@ -36,7 +37,7 @@ class AsyncExecutor(abc.ABC):
self,
request: Request | None,
background_tasks: BackgroundTasks,
organization_id: str,
organization: Organization,
workflow_id: str,
workflow_run_id: str,
max_steps_override: int | None,
@@ -120,7 +121,7 @@ class BackgroundTaskExecutor(AsyncExecutor):
self,
request: Request | None,
background_tasks: BackgroundTasks | None,
organization_id: str,
organization: Organization,
workflow_id: str,
workflow_run_id: str,
max_steps_override: int | None,
@@ -133,10 +134,6 @@ class BackgroundTaskExecutor(AsyncExecutor):
workflow_run_id=workflow_run_id,
)
organization = await app.DATABASE.get_organization(organization_id)
if organization is None:
raise OrganizationNotFound(organization_id)
if background_tasks:
background_tasks.add_task(
app.WORKFLOW_SERVICE.execute_workflow,

View File

@@ -27,12 +27,16 @@ def add_kv_pairs_to_msg(logger: logging.Logger, method_name: str, event_dict: Ev
event_dict["request_id"] = context.request_id
if context.organization_id:
event_dict["organization_id"] = context.organization_id
if context.organization_name:
event_dict["organization_name"] = context.organization_name
if context.task_id:
event_dict["task_id"] = context.task_id
if context.workflow_id:
event_dict["workflow_id"] = context.workflow_id
if context.workflow_run_id:
event_dict["workflow_run_id"] = context.workflow_run_id
if context.workflow_permanent_id:
event_dict["workflow_permanent_id"] = context.workflow_permanent_id
if context.task_v2_id:
event_dict["task_v2_id"] = context.task_v2_id
if context.browser_session_id:

View File

@@ -667,7 +667,7 @@ async def run_workflow_legacy(
workflow_run = await workflow_service.run_workflow(
workflow_id=workflow_id,
organization_id=current_org.organization_id,
organization=current_org,
workflow_request=workflow_request,
template=template,
version=version,
@@ -1634,7 +1634,7 @@ async def run_workflow(
)
workflow_run = await workflow_service.run_workflow(
workflow_id=workflow_id,
organization_id=current_org.organization_id,
organization=current_org,
workflow_request=legacy_workflow_request,
template=template,
version=None,

View File

@@ -128,4 +128,5 @@ async def _get_current_org_cached(x_api_key: str, db: AgentDB) -> Organization:
context = skyvern_context.current()
if context:
context.organization_id = organization.organization_id
context.organization_name = organization.organization_name
return organization

View File

@@ -2497,6 +2497,9 @@ class TaskV2Block(Block):
skyvern_context.set(
skyvern_context.SkyvernContext(
organization_id=organization_id,
organization_name=organization.organization_name,
workflow_id=workflow_run.workflow_id,
workflow_permanent_id=workflow_run.workflow_permanent_id,
workflow_run_id=workflow_run_id,
browser_session_id=browser_session_id,
)

View File

@@ -102,7 +102,7 @@ class WorkflowService:
request_id: str | None,
workflow_request: WorkflowRequestBody,
workflow_permanent_id: str,
organization_id: str,
organization: Organization,
is_template_workflow: bool = False,
version: int | None = None,
max_steps_override: int | None = None,
@@ -121,7 +121,7 @@ class WorkflowService:
# Validate the workflow and the organization
workflow = await self.get_workflow_by_permanent_id(
workflow_permanent_id=workflow_permanent_id,
organization_id=None if is_template_workflow else organization_id,
organization_id=None if is_template_workflow else organization.organization_id,
version=version,
)
if workflow is None:
@@ -137,7 +137,7 @@ class WorkflowService:
workflow_request=workflow_request,
workflow_permanent_id=workflow_permanent_id,
workflow_id=workflow_id,
organization_id=organization_id,
organization_id=organization.organization_id,
parent_workflow_run_id=parent_workflow_run_id,
)
LOG.info(
@@ -151,7 +151,8 @@ class WorkflowService:
)
skyvern_context.set(
SkyvernContext(
organization_id=organization_id,
organization_id=organization.organization_id,
organization_name=organization.organization_name,
request_id=request_id,
workflow_id=workflow_id,
workflow_run_id=workflow_run.workflow_run_id,