forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodos.py
More file actions
42 lines (31 loc) · 1.12 KB
/
Copy pathtodos.py
File metadata and controls
42 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from uuid import uuid4
from pydantic import BaseModel
from strands import tool
class Todo(BaseModel):
id: str = ""
title: str
description: str
emoji: str
status: str = "pending" # "pending" | "completed"
@tool
def manage_todos(todos: list[Todo]) -> str:
"""Manage the current todos.
IMPORTANT: Always pass the full list, not just new items. Each todo
should have a title, description, emoji, and status (pending/completed).
"""
# Strands @tool passes ``model_dump()`` output, so list elements arrive
# as plain dicts. Rehydrate before accessing fields.
todos = [Todo.model_validate(t) for t in todos]
for todo in todos:
if not todo.id:
todo.id = str(uuid4())
return "Successfully updated todos"
@tool
def get_todos() -> str:
"""Get the current todos.
The current list is injected into the prompt by the state context
builder, so this tool just acknowledges that and tells the model to
read it from there.
"""
return "See the current todos list already provided in the conversation context."
todo_tools = [manage_todos, get_todos]