TODO liste avant LLM
Affichée juste avant dans un System message
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from langchain.tools import tool
|
||||
from langgraph.prebuilt import InjectedState
|
||||
from langchain_core.tools import InjectedToolCallId
|
||||
from langchain_core.messages import ToolMessage
|
||||
from langgraph.types import Command
|
||||
from tavily import TavilyClient
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Annotated
|
||||
@@ -60,20 +63,18 @@ def write_file(file_path:str, content: str, append:bool=True) -> str:
|
||||
return f"Erreur lors de l'écriture: {str(e)}"
|
||||
|
||||
@tool
|
||||
def editTodo(index:int, todoState:int, state: Annotated[dict, InjectedState])->bool: # https://stackoverflow.com/a/79525434
|
||||
def editTodo(index:int, todoState:int, state: Annotated[dict, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])->Command: # https://stackoverflow.com/a/79525434
|
||||
"""
|
||||
Modifier l'état d'une tâche (TODO)
|
||||
|
||||
Args:
|
||||
index (int): Index de la tâche à modifier, en commançant à 0 pour la première tâche.
|
||||
todoState (int): Nouvel état. 0 pour "non commencé, 1 pour "en cours", 2 pour "complété"
|
||||
|
||||
Returns:
|
||||
bool: Réussite de l'opération, ou non.
|
||||
"""
|
||||
if "todo" not in state.keys(): return Command(update={"messages": [ToolMessage(content="Echec!", tool_call_id=tool_call_id)]})
|
||||
if len(state["todo"]) <= index:
|
||||
# Erreur, l'index est trop grand
|
||||
return False
|
||||
return Command(update={"messages": [ToolMessage(content="Index en dehors de la liste, echec!", tool_call_id=tool_call_id)]})
|
||||
|
||||
state["todo"][index].state = todoState # Modification de l'état de cette tâche
|
||||
|
||||
@@ -85,42 +86,46 @@ def editTodo(index:int, todoState:int, state: Annotated[dict, InjectedState])->b
|
||||
break
|
||||
|
||||
if not found: state["todo"] = [] # Toutes les tâches terminées, je peux clear la TODO list du state
|
||||
return True
|
||||
return Command(update={
|
||||
"messages": [ToolMessage(content="Réussite!", tool_call_id=tool_call_id)],
|
||||
"todo": [x for x in state["todo"]] # Update du state, # medium.com/@o39joey/a-comprehensive-guide-to-langgraph-managing-agent-state-with-tools-ae932206c7d7
|
||||
})
|
||||
|
||||
@tool
|
||||
def addTodo(name:str, description:str, state: Annotated[dict, InjectedState])->bool:
|
||||
def addTodo(name:str, description:str, state: Annotated[dict, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])->Command:
|
||||
"""
|
||||
Ajouter une nouvelle tâche/TODO
|
||||
|
||||
Args:
|
||||
name (str): Nom de cette tâche
|
||||
description (str): Une ou deux phrases pour décrire le travail à effectuer dans ce TODO
|
||||
|
||||
Returns:
|
||||
bool: Réussite de l'opération, ou non
|
||||
"""
|
||||
if state["todo"] is None: state["todo"] = []
|
||||
if "todo" not in state.keys(): state["todo"] = []
|
||||
|
||||
state["todo"].append(TodoElement(name, description))
|
||||
return True
|
||||
return Command(update={
|
||||
"messages": [ToolMessage(content="Réussite!", tool_call_id=tool_call_id)],
|
||||
"todo": [x for x in state["todo"]] # Update du state, # medium.com/@o39joey/a-comprehensive-guide-to-langgraph-managing-agent-state-with-tools-ae932206c7d7
|
||||
})
|
||||
|
||||
@tool
|
||||
def removeTodo(index:int, state: Annotated[dict, InjectedState])->bool:
|
||||
def removeTodo(index:int, state: Annotated[dict, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId])->Command:
|
||||
"""
|
||||
Retirer une tâche/TODO de la liste des tâches
|
||||
|
||||
Args:
|
||||
index (int): Position de la tâche dans la liste, commence à 0 pour le premier TODO
|
||||
|
||||
Returns:
|
||||
bool: Réussite de l'opération, ou non
|
||||
"""
|
||||
if "todo" not in state.keys(): return Command(update={"messages": [ToolMessage(content="Echec!", tool_call_id=tool_call_id)]})
|
||||
if len(state["todo"]) <= index:
|
||||
# Erreur, l'index est trop grand
|
||||
return False
|
||||
return Command(update={"messages": [ToolMessage(content="Index en dehors de la liste, echec!", tool_call_id=tool_call_id)]})
|
||||
|
||||
state['todo'].pop(index)
|
||||
return True
|
||||
return Command(update={
|
||||
"messages": [ToolMessage(content="Réussite!", tool_call_id=tool_call_id)],
|
||||
"todo": [x for x in state["todo"]] # Update du state, # medium.com/@o39joey/a-comprehensive-guide-to-langgraph-managing-agent-state-with-tools-ae932206c7d7
|
||||
})
|
||||
|
||||
@tool
|
||||
def read_file(file_path: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user