Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/oss/src/apis/fastapi/agent_templates/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from oss.src.core.mounts.types import MountPathInvalid, MountStorageUnavailable
from oss.src.core.sessions.inputs.types import SessionInputIdempotencyConflict
from oss.src.core.sessions.starts.types import SessionStartNotDurable
from oss.src.core.workflows.types import (
InvalidAgentConfigurationError,
InvalidAgentConnectionError,
InvalidAgentHarnessError,
InvalidAgentInstructionsError,
)


def _response(
Expand Down Expand Up @@ -59,6 +65,20 @@ def template_load_error_response(
*,
unavailable_next_step: str = _LOAD_UNAVAILABLE_NEXT_STEP,
) -> JSONResponse | None:
if isinstance(
exc,
(
InvalidAgentConfigurationError,
InvalidAgentConnectionError,
InvalidAgentHarnessError,
InvalidAgentInstructionsError,
),
):
# The agent the template builds cannot run. Same envelope as the workflow routes.
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=exc.to_detail(),
)
if isinstance(exc, TemplateSourceNotFound):
return _response(
status_code=status.HTTP_404_NOT_FOUND,
Expand Down
5 changes: 5 additions & 0 deletions api/oss/src/apis/fastapi/evaluators/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from oss.src.core.git.utils import build_retrieval_info
from oss.src.apis.fastapi.git.exceptions import handle_git_exceptions
from oss.src.apis.fastapi.workflows.exceptions import handle_workflow_exceptions
from oss.src.core.shared.dtos import (
Reference,
)
Expand Down Expand Up @@ -1530,6 +1531,7 @@ async def retrieve_evaluator_revision(

@intercept_exceptions()
@handle_git_exceptions()
@handle_workflow_exceptions()
async def create_evaluator_revision(
self,
request: Request,
Expand Down Expand Up @@ -1799,6 +1801,7 @@ async def query_evaluator_revisions(
return response

@intercept_exceptions()
@handle_workflow_exceptions()
async def commit_evaluator_revision(
self,
request: Request,
Expand Down Expand Up @@ -2044,6 +2047,7 @@ def __init__(
# SIMPLE EVALUATORS --------------------------------------------------------

@intercept_exceptions()
@handle_workflow_exceptions()
async def create_simple_evaluator(
self,
request: Request,
Expand Down Expand Up @@ -2122,6 +2126,7 @@ async def fetch_simple_evaluator(
return simple_evaluator_response

@intercept_exceptions()
@handle_workflow_exceptions()
async def edit_simple_evaluator(
self,
request: Request,
Expand Down
22 changes: 16 additions & 6 deletions api/oss/src/apis/fastapi/workflows/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from oss.src.core.sharing.types import AgentCreationFailed
from oss.src.core.workflows.types import (
AgentDriveError,
InvalidAgentConfigurationError,
InvalidAgentConnectionError,
InvalidAgentHarnessError,
InvalidAgentInstructionsError,
StaticWorkflowSlug,
)
Expand Down Expand Up @@ -46,10 +48,14 @@ def __init__(self, message: str = "The embedded references could not be resolved
super().__init__(status_code=400, detail=message)


class InvalidAgentInstructionsException(HTTPException):
# 422, like the harness refusal on the commit route: the request is well-formed, the
# configuration in it is not.
def __init__(self, error: InvalidAgentInstructionsError):
class InvalidAgentConfigurationException(HTTPException):
# 422: the request is well-formed, the agent configuration in it cannot run.
def __init__(
self,
error: InvalidAgentConfigurationError
| InvalidAgentHarnessError
| InvalidAgentInstructionsError,
):
super().__init__(status_code=422, detail=error.to_detail())


Expand All @@ -75,8 +81,12 @@ async def wrapper(*args, **kwargs):
raise NonEmbeddableWorkflowReferenceException(message=str(e)) from e
except EmbedError as e:
raise EmbedException(message=str(e)) from e
except InvalidAgentInstructionsError as e:
raise InvalidAgentInstructionsException(e) from e
except (
InvalidAgentConfigurationError,
InvalidAgentHarnessError,
InvalidAgentInstructionsError,
) as e:
raise InvalidAgentConfigurationException(e) from e
except InvalidAgentConnectionError as e:
raise InvalidAgentConnectionException(e) from e
except AgentDriveError as e:
Expand Down
5 changes: 0 additions & 5 deletions api/oss/src/apis/fastapi/workflows/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
WorkflowsService,
SimpleWorkflowsService,
)
from oss.src.core.workflows.types import InvalidAgentHarnessError
from oss.src.core.environments.service import (
EnvironmentsService,
)
Expand Down Expand Up @@ -2044,10 +2043,6 @@ async def _commit_workflow_revision(
)
except RevisionConflictError as e:
raise HTTPException(status_code=409, detail=e.to_detail()) from e
except InvalidAgentHarnessError as e:
# 422, the same status every other "your change is not committable" answer on this
# route uses: the request is well-formed, the configuration in it is not.
raise HTTPException(status_code=422, detail=e.to_detail()) from e
except ChangeSetError as e:
raise HTTPException(status_code=422, detail=e.to_detail()) from e
except EmbedReferenceInconsistentError as e:
Expand Down
12 changes: 8 additions & 4 deletions api/oss/src/core/applications/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from oss.src.core.workflows.service import (
WorkflowsService,
_reject_unreadable_agent_instructions,
_reject_unrunnable_agent,
new_agent_policy,
)

Expand Down Expand Up @@ -1097,7 +1097,7 @@ async def create(
) -> Optional[SimpleApplication]:
# Before the artifact exists: refusing only at the final commit would leave the
# artifact, variant, and blank revision behind.
_reject_unreadable_agent_instructions(simple_application_create.data)
_reject_unrunnable_agent(simple_application_create.data)
await self.applications_service.workflows_service.reject_unusable_agent_drives(
project_id=project_id,
data=simple_application_create.data,
Expand Down Expand Up @@ -1343,7 +1343,7 @@ async def edit(
first_agent_owner_user_id: Optional[UUID] = None,
) -> Optional[SimpleApplication]:
# Before any write: a refusal at the final commit would leave earlier writes behind.
_reject_unreadable_agent_instructions(simple_application_edit.data)
_reject_unrunnable_agent(simple_application_edit.data)

application = await self.applications_service.fetch_application(
project_id=project_id,
Expand All @@ -1366,7 +1366,7 @@ async def edit(
should_commit_revision = bool(simple_application_edit.model_fields_set - {"id"})

# The data the commit stores, chosen once and checked before the first write.
application_revision_data = None
application_revision_data: Optional[ApplicationRevisionData] = None
if should_commit_revision:
if simple_application_edit.data:
application_revision_data = ApplicationRevisionData(
Expand All @@ -1386,6 +1386,10 @@ async def edit(

application_revision_data = latest_application_revision.data
Comment thread
mmabrouk marked this conversation as resolved.
Resolved

# The commit below carries the stored data, so it is refused for the same
# reason. Refuse it here, before the artifact write.
_reject_unrunnable_agent(application_revision_data)

await self.applications_service.workflows_service.reject_unusable_agent_drives(
project_id=project_id,
data=application_revision_data,
Expand Down
9 changes: 8 additions & 1 deletion api/oss/src/core/evaluators/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
validate_variant_refs_sufficient,
validate_retrieve_refs_consistent,
)
from oss.src.core.workflows.service import WorkflowsService
from oss.src.core.workflows.service import WorkflowsService, _reject_unrunnable_agent

# Resolution is now handled by EmbedsService
from oss.src.core.embeds.dtos import ResolutionInfo, ErrorPolicy
Expand Down Expand Up @@ -1160,6 +1160,10 @@ async def create(
#
first_agent_owner_user_id: Optional[UUID] = None,
) -> Optional[SimpleEvaluator]:
# Before the artifact exists: refusing only at the final commit would leave the
# artifact, variant, and blank revision behind.
_reject_unrunnable_agent(simple_evaluator_create.data)

simple_evaluator_flag_values = _dump_flags(simple_evaluator_create.flags)
simple_evaluator_flag_values.pop("is_evaluator", None)
simple_evaluator_flags = SimpleEvaluatorFlags(
Expand Down Expand Up @@ -1422,6 +1426,9 @@ async def edit(
#
first_agent_owner_user_id: Optional[UUID] = None,
) -> Optional[SimpleEvaluator]:
# Before any write: a refusal at the final commit would leave earlier writes behind.
_reject_unrunnable_agent(simple_evaluator_edit.data)

simple_evaluator_flags = (
SimpleEvaluatorFlags(
**{
Expand Down
3 changes: 3 additions & 0 deletions api/oss/src/core/tools/platform_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ async def handle_commit_revision(
from oss.src.core.workflows.service import RevisionConflictError
from oss.src.core.workflows.types import (
AgentDriveError,
InvalidAgentConfigurationError,
InvalidAgentConnectionError,
InvalidAgentHarnessError,
InvalidAgentInstructionsError,
Expand Down Expand Up @@ -934,6 +935,8 @@ async def handle_commit_revision(
)
except ChangeSetError as e:
return PlatformHandlerResult.failure(AgentError(**e.to_detail()))
except InvalidAgentConfigurationError as e:
return PlatformHandlerResult.failure(AgentError(**e.to_detail()))
except InvalidAgentHarnessError as e:
return PlatformHandlerResult.failure(AgentError(**e.to_detail()))
except InvalidAgentInstructionsError as e:
Expand Down
19 changes: 14 additions & 5 deletions api/oss/src/core/workflows/change_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
contract is authoritative; this module is its executable half.

The engine is dependency-free: plain dicts in, a plain result out, no pydantic, no I/O, no
database. Two wrappers call it. The commit wrapper checks ``base_revision_id`` against the
head and persists; the invoke-override wrapper resolves an immutable revision, applies with
the ``parameters``-only scope policy, and persists nothing.
database. Its one import from the SDK is a constant: the tool types the runtime allows once
per list, which the engine keys by type. Two wrappers call it. The commit wrapper checks
``base_revision_id`` against the head and persists; the invoke-override wrapper resolves an
immutable revision, applies with the ``parameters``-only scope policy, and persists nothing.

Three things belong to the wrapper, not here, and the contract says so: the selector
normalization (contract 4.3), the platform-tool rejection (11), the derived commit message
Expand All @@ -20,6 +21,8 @@
from difflib import SequenceMatcher
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union

from agenta.sdk.agents.tools import SINGLE_ENTRY_TOOL_TYPES

__all__ = [
"ChangeSetError",
"ChangeSetResult",
Expand Down Expand Up @@ -129,7 +132,8 @@ class Reason:
Reason.ITEM_NOT_FOUND: (
"Call read_config with a {list, key} selector for that list: its refusal lists "
"every key the list actually holds. A gateway_connection entry's key is "
"gateway_connection:<connection.provider>:<connection.integration>."
"gateway_connection:<connection.provider>:<connection.integration>; an "
"agenta_tools entry's key is agenta_tools."
),
Reason.ITEM_RENAME_NOT_ALLOWED: (
"Send remove_item for the old key, then add_item with the new value."
Expand All @@ -143,7 +147,7 @@ class Reason:
"file. For a tool the key depends on its type: gateway_connection needs "
"connection.provider and connection.integration (together they are its key); "
"gateway needs an explicit name; reference needs name or slug; platform is keyed "
"by op; everything else needs name."
"by op; agenta_tools is keyed agenta_tools; everything else needs name."
),
Reason.UNKEYED_COLLECTION: (
"That list is not addressed by name. Use set to replace the whole list."
Expand Down Expand Up @@ -471,6 +475,11 @@ def _tool_name(entry: Dict[str, Any], *, allow_legacy_fallback: bool) -> Optiona
return entry.get("name") or entry.get("slug")
if kind == "platform":
return entry.get("op")
if isinstance(kind, str) and kind in SINGLE_ENTRY_TOOL_TYPES:
# A type the runtime allows once per list has no name, so its type is its key, and
# an operation can reach inside the entry instead of replacing the whole list around
# it. A legacy list holding two is a duplicate key, which the engine already reports.
return kind
Comment thread
mmabrouk marked this conversation as resolved.
Resolved
return entry.get("name")


Expand Down
Loading
Loading