Skip to content

Commit c1c280f

Browse files
authored
Merge pull request #116 from kazmer97/feat/create-common-strands-utils
extract generic tools from agentic idp
2 parents 8102c41 + ce8eca8 commit c1c280f

File tree

2 files changed

+84
-71
lines changed

2 files changed

+84
-71
lines changed

lib/idp_common_pkg/idp_common/extraction/agentic_idp.py

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
)
3838

3939
from idp_common.bedrock.client import CACHEPOINT_SUPPORTED_MODELS
40+
from idp_common.utils.strands_agent_tools.todo_list import (
41+
create_todo_list,
42+
update_todo,
43+
view_todo_list,
44+
)
4045

4146
# Use AWS Lambda Powertools Logger for structured logging
4247
# Automatically logs as JSON with Lambda context, request_id, timestamp, etc.
@@ -404,77 +409,6 @@ def patch_buffer_data(patches: list[dict[str, Any]], agent: Agent) -> str:
404409
return f"Successfully patched {str(patched_data)[100:]}...."
405410

406411

407-
@tool
408-
def create_todo_list(todos: list[str], agent: Agent) -> str:
409-
"""Create a new todo list to track your extraction tasks. Use this to plan your work, especially for large documents.
410-
411-
Args:
412-
todos: List of task descriptions to track (e.g., ["Extract rows 1-100", "Extract rows 101-200"])
413-
414-
Example:
415-
create_todo_list(["Extract first 100 rows", "Extract rows 101-200", "Extract rows 201-300", "Validate and finalize"], agent)
416-
"""
417-
todo_list = [{"task": task, "completed": False} for task in todos]
418-
agent.state.set("todo_list", todo_list)
419-
logger.info("Created todo list", extra={"todo_count": len(todo_list)})
420-
return f"Created todo list with {len(todo_list)} tasks:\n" + "\n".join(
421-
f"{i + 1}. [ ] {item['task']}" for i, item in enumerate(todo_list)
422-
)
423-
424-
425-
@tool
426-
def update_todo(task_index: int, completed: bool, agent: Agent) -> str:
427-
"""Mark a todo item as completed or not completed.
428-
429-
Args:
430-
task_index: Index of the task to update (1-based, matching the list display)
431-
completed: True to mark as completed, False to mark as incomplete
432-
433-
Example:
434-
update_todo(1, True, agent) # Mark first task as completed
435-
"""
436-
todo_list: list[dict[str, Any]] | None = agent.state.get("todo_list")
437-
438-
if not todo_list:
439-
return "No todo list found. Create one first using create_todo_list."
440-
441-
# Convert to 0-based index
442-
index = task_index - 1
443-
444-
if index < 0 or index >= len(todo_list):
445-
return f"Invalid task index {task_index}. Valid range: 1-{len(todo_list)}"
446-
447-
todo_list[index]["completed"] = completed
448-
agent.state.set("todo_list", todo_list)
449-
450-
status = "completed" if completed else "incomplete"
451-
logger.info(
452-
f"Updated todo {task_index}",
453-
extra={"task": todo_list[index]["task"], "completed": completed},
454-
)
455-
return f"Task {task_index} marked as {status}: {todo_list[index]['task']}"
456-
457-
458-
@tool
459-
def view_todo_list(agent: Agent) -> str:
460-
"""View your current todo list with completion status."""
461-
todo_list: list[dict[str, Any]] | None = agent.state.get("todo_list")
462-
463-
if not todo_list:
464-
return "No todo list found. Create one using create_todo_list to track your extraction tasks."
465-
466-
completed_count = sum(1 for item in todo_list if item["completed"])
467-
total_count = len(todo_list)
468-
469-
result = f"Todo List ({completed_count}/{total_count} completed):\n"
470-
result += "\n".join(
471-
f"{i + 1}. [{'✓' if item['completed'] else ' '}] {item['task']}"
472-
for i, item in enumerate(todo_list)
473-
)
474-
475-
return result
476-
477-
478412
SYSTEM_PROMPT = """
479413
You are a useful assistant that helps turn unstructured data into structured data using the provided tools.
480414
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
from aws_lambda_powertools import Logger
3+
from typing_extensions import Any
4+
from strands import Agent, tool
5+
6+
logger = Logger(service="agentic_idp", level=os.getenv("LOG_LEVEL", "INFO"))
7+
8+
@tool
9+
def update_todo(task_index: int, completed: bool, agent: Agent) -> str:
10+
"""Mark a todo item as completed or not completed.
11+
12+
Args:
13+
task_index: Index of the task to update (1-based, matching the list display)
14+
completed: True to mark as completed, False to mark as incomplete
15+
16+
Example:
17+
update_todo(1, True, agent) # Mark first task as completed
18+
"""
19+
todo_list: list[dict[str, Any]] | None = agent.state.get("todo_list")
20+
21+
if not todo_list:
22+
return "No todo list found. Create one first using create_todo_list."
23+
24+
# Convert to 0-based index
25+
index = task_index - 1
26+
27+
if index < 0 or index >= len(todo_list):
28+
return f"Invalid task index {task_index}. Valid range: 1-{len(todo_list)}"
29+
30+
todo_list[index]["completed"] = completed
31+
agent.state.set("todo_list", todo_list)
32+
33+
status = "completed" if completed else "incomplete"
34+
logger.info(
35+
f"Updated todo {task_index}",
36+
extra={"task": todo_list[index]["task"], "completed": completed},
37+
)
38+
return f"Task {task_index} marked as {status}: {todo_list[index]['task']}"
39+
40+
41+
42+
43+
@tool
44+
def view_todo_list(agent: Agent) -> str:
45+
"""View your current todo list with completion status."""
46+
todo_list: list[dict[str, Any]] | None = agent.state.get("todo_list")
47+
48+
if not todo_list:
49+
return "No todo list found. Create one using create_todo_list to track your extraction tasks."
50+
51+
completed_count = sum(1 for item in todo_list if item["completed"])
52+
total_count = len(todo_list)
53+
54+
result = f"Todo List ({completed_count}/{total_count} completed):\n"
55+
result += "\n".join(
56+
f"{i + 1}. [{'✓' if item['completed'] else ' '}] {item['task']}"
57+
for i, item in enumerate(todo_list)
58+
)
59+
60+
return result
61+
62+
63+
64+
@tool
65+
def create_todo_list(todos: list[str], agent: Agent) -> str:
66+
"""Create a new todo list to track your extraction tasks. Use this to plan your work, especially for large documents.
67+
68+
Args:
69+
todos: List of task descriptions to track (e.g., ["Extract rows 1-100", "Extract rows 101-200"])
70+
71+
Example:
72+
create_todo_list(["Extract first 100 rows", "Extract rows 101-200", "Extract rows 201-300", "Validate and finalize"], agent)
73+
"""
74+
todo_list = [{"task": task, "completed": False} for task in todos]
75+
agent.state.set("todo_list", todo_list)
76+
logger.info("Created todo list", extra={"todo_count": len(todo_list)})
77+
return f"Created todo list with {len(todo_list)} tasks:\n" + "\n".join(
78+
f"{i + 1}. [ ] {item['task']}" for i, item in enumerate(todo_list)
79+
)

0 commit comments

Comments
 (0)