Skip to content
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

sdk-py: added Cron search functionality #804

Merged
merged 28 commits into from
Jun 28, 2024
Merged
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
19 changes: 19 additions & 0 deletions libs/sdk-py/langgraph_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from langgraph_sdk.schema import (
Assistant,
Config,
Cron,
vbarda marked this conversation as resolved.
Show resolved Hide resolved
GraphSchema,
Metadata,
MultitaskStrategy,
Expand Down Expand Up @@ -718,6 +719,24 @@ async def delete(self, cron_id: str) -> None:
"""Delete a cron."""
await self.http.delete(f"/runs/crons/{cron_id}")

async def search(
self,
*,
assistant_id: Optional[str] = None,
thread_id: Optional[str] = None,
limit: int = 10,
offset: int = 0,
) -> list[Cron]:
"""Get a list of cron jobs."""
payload = {
"assistant_id": assistant_id,
"thread_id": thread_id,
"limit": limit,
"offset": offset,
}
payload = {k: v for k, v in payload.items() if v is not None}
return await self.http.post("/runs/crons/search", json=payload)


def _get_api_key(api_key: Optional[str] = None) -> Optional[str]:
"""Get the API key from the environment.
Expand Down
17 changes: 17 additions & 0 deletions libs/sdk-py/langgraph_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,20 @@ class Run(TypedDict):
"""The run metadata."""
multitask_strategy: MultitaskStrategy
"""Strategy to handle concurrent runs on the same thread."""


class Cron(TypedDict):
cron_id: str
"""The ID of the cron."""
thread_id: Optional[str]
"""The ID of the thread."""
end_time: Optional[datetime]
"""The end date to stop running the cron."""
schedule: str
"""The schedule to run, cron format."""
created_at: datetime
"""The time the cron was created."""
updated_at: datetime
"""The last time the cron was updated."""
payload: dict
"""The run payload to use for creating new run."""
Loading