Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.5 KB
Raw Blame
"""
Facade re-exports for the multi-turn agent machinery.

The custom-prompt agent surface (sandbox context, the multi-turn session driver, the
create/poll primitives, local-dev helpers) is shared behavioral infrastructure that other
products (signals, conversations, evals) build agentic flows on. It crosses the boundary as
objects, not data, per the wiring pattern. Heavy by import, so it lives here rather than in
``facade/api.py``.
"""

from products.tasks.backend.constants import EVAL_INTERACTION_ORIGIN, MCP_EXEC_SKILLS_FEATURE_FLAG
from products.tasks.backend.logic.services.custom_prompt_internals import (
    AgentTurnFailed,
    CustomPromptSandboxContext,
    EmptyAgentTurnError,
    OutputFn,
    RepositoryContextUnavailable,
    SandboxRunFailed,
    TruncatedAgentOutputError,
    TurnPollResult,
    TurnPollTimeout,
    create_task_and_trigger,
    extract_json_from_text,
    poll_for_agent_task as poll_for_turn,
)
from products.tasks.backend.logic.services.custom_prompt_multi_turn_runner import (
    MultiTurnSession,
    turn_failure_error_type,
)
from products.tasks.backend.logic.services.dev_sandbox_context import resolve_sandbox_context_for_local_dev
from products.tasks.backend.logic.services.local_skills import (
    ENV_DISABLE_BUNDLED_SKILLS,
    ENV_LOCAL_SKILLS_HOST_PATH,
    LocalSkillsCache,
)
from products.tasks.backend.logic.services.startup_failure import AgentStartupFailed
from products.tasks.backend.models import SandboxEnvironment


def create_skill_isolation_environment(*, team_id: int, user_id: int, name: str) -> str:
    """Create an internal environment that disables native bundled skills for an agent run."""
    environment = SandboxEnvironment.objects.create(
        team_id=team_id,
        created_by_id=user_id,
        name=name,
        environment_variables={ENV_DISABLE_BUNDLED_SKILLS: "1"},
        internal=True,
    )
    return str(environment.id)


__all__ = [
    "ENV_DISABLE_BUNDLED_SKILLS",
    "EVAL_INTERACTION_ORIGIN",
    "MCP_EXEC_SKILLS_FEATURE_FLAG",
    "ENV_LOCAL_SKILLS_HOST_PATH",
    "AgentTurnFailed",
    "AgentStartupFailed",
    "RepositoryContextUnavailable",
    "CustomPromptSandboxContext",
    "EmptyAgentTurnError",
    "LocalSkillsCache",
    "MultiTurnSession",
    "OutputFn",
    "SandboxRunFailed",
    "TruncatedAgentOutputError",
    "TurnPollResult",
    "TurnPollTimeout",
    "create_task_and_trigger",
    "create_skill_isolation_environment",
    "extract_json_from_text",
    "poll_for_turn",
    "resolve_sandbox_context_for_local_dev",
    "turn_failure_error_type",
]