diff --git a/AgentReact/agent.py b/AgentReact/agent.py index 39464fd..a21475d 100644 --- a/AgentReact/agent.py +++ b/AgentReact/agent.py @@ -1,8 +1,9 @@ from langgraph.graph import START, END from langgraph.graph.state import CompiledStateGraph -from utils.nodes import reponse_question, tool_node, should_continue +from utils.nodes import call_to_LLM, should_continue, task_ended, BasicToolNode, tool_node from utils.state import getState +from utils.tools import getTools def getGraph()->CompiledStateGraph: """ @@ -14,15 +15,15 @@ def getGraph()->CompiledStateGraph: workflow = getState() # State prêt à utiliser # Définition des sommets du graphe - workflow.add_node(reponse_question) - workflow.add_node("tool_node", tool_node) # N'est pas une fonction, mais une classe instanciée, je dois précisier le nom du node + workflow.add_node(call_to_LLM) + workflow.add_node("tool_node", tool_node)# BasicToolNode(tools=getTools())) # N'est pas une fonction, mais une classe instanciée, je dois précisier le nom du node # Arrêtes - workflow.set_entry_point("reponse_question") - workflow.add_edge("tool_node", "reponse_question") - workflow.add_conditional_edges("reponse_question", should_continue, { + workflow.set_entry_point("call_to_LLM") + workflow.add_edge("tool_node", "call_to_LLM") + workflow.add_conditional_edges("call_to_LLM", should_continue, { "tools":"tool_node", - END:END + "no_tools":END }) return workflow.compile() diff --git a/AgentReact/start.py b/AgentReact/start.py index 6ad670a..96e66a4 100644 --- a/AgentReact/start.py +++ b/AgentReact/start.py @@ -10,6 +10,6 @@ from agent import getGraph mlflow.set_experiment("TEST PROJET") # VOIR AVEC LA COMMANDE "MLFLOW SERVER" mlflow.langchain.autolog() -out_state = getGraph().invoke({'messages':[HumanMessage("What's the price for bitcoin ?")]}) +out_state = getGraph().invoke({'messages':[HumanMessage("Observe la base de documents, et génère un rapport de stage à partir de celle-ci. Ecris le dans un fichier markdown.")]}) for message in out_state['messages']: message.pretty_print() \ No newline at end of file diff --git a/AgentReact/utils/nodes.py b/AgentReact/utils/nodes.py index 5703dc7..5171f9a 100644 --- a/AgentReact/utils/nodes.py +++ b/AgentReact/utils/nodes.py @@ -53,6 +53,8 @@ def task_ended(state: MessagesState): return END return "continue" +tool_node = ToolNode(tools=getTools()) + class BasicToolNode: # De mon ancien projet, https://github.com/LJ5O/Assistant/blob/main/modules/Brain/src/LLM/graph/nodes/BasicToolNode.py """A node that runs the tools requested in the last AIMessage.""" diff --git a/AgentReact/utils/tools.py b/AgentReact/utils/tools.py index d742359..1d9fef3 100644 --- a/AgentReact/utils/tools.py +++ b/AgentReact/utils/tools.py @@ -48,13 +48,13 @@ 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, state:int, state: Annotated[dict, InjectedState])->bool: # https://stackoverflow.com/a/79525434 +def editTodo(index:int, todoState:int, state: Annotated[dict, InjectedState])->bool: # 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. - state (int): Nouvel état. 0 pour "non commencé, 1 pour "en cours", 2 pour "complété" + 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. @@ -63,7 +63,7 @@ def editTodo(index:int, state:int, state: Annotated[dict, InjectedState])->bool: # Erreur, l'index est trop grand return False - state["todo"][index].state = state # Modification de l'état de cette tâche + state["todo"][index].state = todoState # Modification de l'état de cette tâche # Toutes les tâches complétées ? found = False @@ -168,9 +168,9 @@ def search_in_files(query:str, state: Annotated[dict, InjectedState])->str: Returns: str: Échantillons de documents correspondants, concaténés en une seule chaîne de caractères. """ - bdd = VectorDatabase() # Récupère l'unique instance de cette BDD, c'est un SIngleton + bdd = VectorDatabase.getChroma() # Récupère l'unique instance de cette BDD, c'est un SIngleton - retrieved_docs = bdd.getChroma().similarity_search(query, k=5) # 5 documents + retrieved_docs = bdd.similarity_search(query, k=5) # 5 documents # Conversion des documents en texte docs_content = "\n".join( diff --git a/agent.png b/agent.png new file mode 100644 index 0000000..c920050 Binary files /dev/null and b/agent.png differ diff --git a/roadmap.md b/roadmap.md index eefaeba..92a67ef 100644 --- a/roadmap.md +++ b/roadmap.md @@ -14,8 +14,9 @@ - [X] Préparation du `State` - [X] Développement des outils de l'agent - [X] Préparation des nœuds -- [ ] Branchement des nœuds entre-eux +- [X] Branchement des nœuds entre-eux, **MVP** - [ ] Human in the loop +- [ ] Amélioration du workflow ## Amélioration de l'agent - [ ] Cross-encoding sur la sortie du **RAG**