-
Notifications
You must be signed in to change notification settings - Fork 3
[SILO-766] feat: add Agent Runs API and related models, activities, and tests #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Saurabhkmr98
wants to merge
2
commits into
main
Choose a base branch
from
feat-agent_sessions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ venv/ | |
| .venv/ | ||
| .python-version | ||
| .pytest_cache | ||
| .env | ||
|
|
||
| # Translations | ||
| *.mo | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from .base import AgentRuns | ||
|
|
||
| __all__ = ["AgentRuns"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| from collections.abc import Mapping | ||
| from typing import Any | ||
|
|
||
| from ...models.agent_runs import ( | ||
| AgentRunActivity, | ||
| CreateAgentRunActivity, | ||
| PaginatedAgentRunActivityResponse, | ||
| ) | ||
| from ..base_resource import BaseResource | ||
|
|
||
|
|
||
| class AgentRunActivities(BaseResource): | ||
| """Agent Run Activities API resource. | ||
|
|
||
| Handles all agent run activity operations. | ||
| """ | ||
|
|
||
| def __init__(self, config: Any) -> None: | ||
| super().__init__(config, "/workspaces/") | ||
|
|
||
| def list( | ||
| self, | ||
| workspace_slug: str, | ||
| run_id: str, | ||
| params: Mapping[str, Any] | None = None, | ||
| ) -> PaginatedAgentRunActivityResponse: | ||
| """List activities for an agent run. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| run_id: UUID of the agent run | ||
| params: Optional query parameters for pagination (per_page, cursor) | ||
|
|
||
| Returns: | ||
| Paginated list of agent run activities | ||
| """ | ||
| response = self._get( | ||
| f"{workspace_slug}/runs/{run_id}/activities", | ||
| params=params, | ||
| ) | ||
| return PaginatedAgentRunActivityResponse.model_validate(response) | ||
|
|
||
| def retrieve( | ||
| self, | ||
| workspace_slug: str, | ||
| run_id: str, | ||
| activity_id: str, | ||
| ) -> AgentRunActivity: | ||
| """Retrieve a specific agent run activity by ID. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| run_id: UUID of the agent run | ||
| activity_id: UUID of the activity | ||
|
|
||
| Returns: | ||
| The agent run activity | ||
| """ | ||
| response = self._get( | ||
| f"{workspace_slug}/runs/{run_id}/activities/{activity_id}" | ||
| ) | ||
| return AgentRunActivity.model_validate(response) | ||
|
|
||
| def create( | ||
| self, | ||
| workspace_slug: str, | ||
| run_id: str, | ||
| data: CreateAgentRunActivity, | ||
| ) -> AgentRunActivity: | ||
| """Create a new agent run activity. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| run_id: UUID of the agent run | ||
| data: The activity data to create | ||
|
|
||
| Returns: | ||
| The created agent run activity | ||
| """ | ||
| response = self._post( | ||
| f"{workspace_slug}/runs/{run_id}/activities", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return AgentRunActivity.model_validate(response) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from typing import Any | ||
|
|
||
| from ...models.agent_runs import AgentRun, CreateAgentRun | ||
| from ..base_resource import BaseResource | ||
| from .activities import AgentRunActivities | ||
|
|
||
|
|
||
| class AgentRuns(BaseResource): | ||
| """Agent Runs API resource. | ||
|
|
||
| Handles all agent run operations. | ||
| """ | ||
|
|
||
| def __init__(self, config: Any) -> None: | ||
| super().__init__(config, "/workspaces/") | ||
|
|
||
| # Initialize sub-resources | ||
| self.activities = AgentRunActivities(config) | ||
|
|
||
| def create( | ||
| self, | ||
| workspace_slug: str, | ||
| data: CreateAgentRun, | ||
| ) -> AgentRun: | ||
| """Create a new agent run. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| data: The agent run data to create | ||
|
|
||
| Returns: | ||
| The created agent run | ||
| """ | ||
| response = self._post( | ||
| f"{workspace_slug}/runs", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return AgentRun.model_validate(response) | ||
|
|
||
| def retrieve( | ||
| self, | ||
| workspace_slug: str, | ||
| run_id: str, | ||
| ) -> AgentRun: | ||
| """Retrieve an agent run by ID. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| run_id: UUID of the agent run | ||
|
|
||
| Returns: | ||
| The agent run | ||
| """ | ||
| response = self._get(f"{workspace_slug}/runs/{run_id}") | ||
| return AgentRun.model_validate(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from enum import Enum | ||
| from typing import Any, Literal | ||
|
|
||
| from pydantic import BaseModel, ConfigDict | ||
|
|
||
|
|
||
| class AgentRunStatus(str, Enum): | ||
| """Agent run status enum.""" | ||
|
|
||
| CREATED = "created" | ||
| IN_PROGRESS = "in_progress" | ||
| AWAITING = "awaiting" | ||
| COMPLETED = "completed" | ||
| STOPPING = "stopping" | ||
| STOPPED = "stopped" | ||
| FAILED = "failed" | ||
| STALE = "stale" | ||
|
|
||
|
|
||
| class AgentRunType(str, Enum): | ||
| """Agent run type enum.""" | ||
|
|
||
| COMMENT_THREAD = "comment_thread" | ||
|
|
||
|
|
||
| class AgentRunActivitySignal(str, Enum): | ||
| """Agent run activity signal enum.""" | ||
|
|
||
| AUTH_REQUEST = "auth_request" | ||
| CONTINUE = "continue" | ||
| SELECT = "select" | ||
| STOP = "stop" | ||
|
|
||
|
|
||
| class AgentRunActivityType(str, Enum): | ||
| """Agent run activity type enum.""" | ||
|
|
||
| ACTION = "action" | ||
| ELICITATION = "elicitation" | ||
| ERROR = "error" | ||
| PROMPT = "prompt" | ||
| RESPONSE = "response" | ||
| THOUGHT = "thought" | ||
|
|
||
|
|
||
| class AgentRun(BaseModel): | ||
| """Agent Run model.""" | ||
|
|
||
| model_config = ConfigDict(extra="allow", populate_by_name=True) | ||
|
|
||
| id: str | ||
| agent_user: str | ||
| comment: str | None = None | ||
| source_comment: str | None = None | ||
| creator: str | ||
| stopped_at: str | None = None | ||
| stopped_by: str | None = None | ||
| started_at: str | ||
| ended_at: str | None = None | ||
| external_link: str | None = None | ||
| issue: str | None = None | ||
| workspace: str | ||
| project: str | None = None | ||
| status: AgentRunStatus | ||
| error_metadata: dict[str, Any] | None = None | ||
| type: AgentRunType | ||
| created_at: str | None = None | ||
| updated_at: str | None = None | ||
|
|
||
|
|
||
| class CreateAgentRun(BaseModel): | ||
| """Create agent run request model.""" | ||
|
|
||
| model_config = ConfigDict(extra="ignore", populate_by_name=True) | ||
|
|
||
| agent_slug: str | ||
| issue: str | None = None | ||
| project: str | None = None | ||
| comment: str | None = None | ||
| source_comment: str | None = None | ||
| external_link: str | None = None | ||
| type: AgentRunType | None = None | ||
|
|
||
|
|
||
| class AgentRunActivityActionContent(BaseModel): | ||
| """Agent run activity content for action type.""" | ||
|
|
||
| model_config = ConfigDict(extra="allow", populate_by_name=True) | ||
|
|
||
| type: Literal["action"] | ||
| action: str | ||
| parameters: dict[str, str] | ||
|
|
||
|
|
||
| class AgentRunActivityTextContent(BaseModel): | ||
| """Agent run activity content for non-action types.""" | ||
|
|
||
| model_config = ConfigDict(extra="allow", populate_by_name=True) | ||
|
|
||
| type: Literal["elicitation", "error", "prompt", "response", "thought"] | ||
| body: str | ||
|
|
||
|
|
||
| AgentRunActivityContent = AgentRunActivityActionContent | AgentRunActivityTextContent | ||
|
|
||
|
|
||
| class AgentRunActivity(BaseModel): | ||
| """Agent Run Activity model.""" | ||
|
|
||
| model_config = ConfigDict(extra="allow", populate_by_name=True) | ||
|
|
||
| id: str | ||
| agent_run: str | ||
| content: AgentRunActivityContent | ||
| content_metadata: dict[str, Any] | None = None | ||
| ephemeral: bool | ||
| signal: AgentRunActivitySignal | ||
| signal_metadata: dict[str, Any] | None = None | ||
| comment: str | None = None | ||
| actor: str | None = None | ||
| type: AgentRunActivityType | ||
| project: str | None = None | ||
| workspace: str | ||
| created_at: str | None = None | ||
| updated_at: str | None = None | ||
|
|
||
|
|
||
| class CreateAgentRunActivity(BaseModel): | ||
| """Create agent run activity request model.""" | ||
|
|
||
| model_config = ConfigDict(extra="ignore", populate_by_name=True) | ||
|
|
||
| content: AgentRunActivityContent | ||
| content_metadata: dict[str, Any] | None = None | ||
| signal: AgentRunActivitySignal | None = None | ||
| signal_metadata: dict[str, Any] | None = None | ||
| type: Literal["action", "elicitation", "error", "response", "thought"] | ||
| project: str | None = None | ||
|
|
||
|
|
||
| class PaginatedAgentRunActivityResponse(BaseModel): | ||
| """Paginated agent run activity response.""" | ||
|
|
||
| model_config = ConfigDict(extra="allow", populate_by_name=True) | ||
|
|
||
| results: list[AgentRunActivity] | ||
| next_cursor: str | None = None | ||
| prev_cursor: str | None = None | ||
| next_page_results: bool | None = None | ||
| prev_page_results: bool | None = None | ||
| count: int | None = None | ||
| total_pages: int | None = None | ||
| total_results: int | None = None | ||
| extra_stats: dict[str, Any] | None = None | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 1599
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 164
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 1461
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 52
Move docstring to immediately follow the function signature.
The docstring on line 85 appears after the skip logic instead of immediately following the function definition on line 81. Move it to line 82 to follow Python convention.
Unlike the
projectfixture, cleanup is not feasible for agent runs because the AgentRuns API does not expose a delete method—onlycreate()andretrieve()are available.🤖 Prompt for AI Agents