Format: application/x-python-code
⬇ Download File (2.2 KB)
   1  o
   2  
   3  
   4  �h��@s>ddlmZmZmZddlmZddlmZGdd�d�ZdS)�)�Dict�Any�List)�query_ollama)�execute_toolc@s�eZdZdd�Zdeddfdd�Zdefdd	�Zd
   5  edeeeffdd�Z	d
   6  ede
   7  fdd�Zdededdfdd�Zdeeefddfdd�Z
   8  dS)�PlannercCsg|_i|_dS�N)�chat_history�context)�self�r�:C:\Users\shubh\Videos\agent\agent\modules\agent\planner.py�__init__s
   9  zPlanner.__init__�
  10  user_input�returnNcCs|jd|d�dS)N�user��role�content)�_update_history)rrrrr
  11  �
  12  receive_input
  13  szPlanner.receive_inputc�sh�d}t|�D]*}t|j|jdd�IdH}d|vr'|�|�IdH}|�|�q|jd|d�|SdS)N��planner)�promptr
  14  �
  15  agent_type�
  16  [ToolCall:�	assistantrz!Maximum processing cycles reached)�rangerr	r
  17  �_handle_tool_call�_update_contextr)rZ
  18  max_cycles�_Zllm_responseZtool_resultrrr
  19  �process
  20  s��zPlanner.process�responsec�sR�|�d�d�d�d��}|�|�\}}t||�IdH}|jdt|�d�|S)Nr��]r�toolr)�split�strip�_parse_tool_callrr�str)rr"�	tool_callZ	tool_name�args�resultrrr
  21  rs�zPlanner._handle_tool_callr*cCs*|�dd�dt|�dd�d�d��fS)N�(r#r�))r&�eval�rstrip)rr*rrr
  22  r(%s*zPlanner._parse_tool_callrrcCs|j�||d��dS)Nr)r	�append)rrrrrr
  23  r(szPlanner._update_history�	tool_datacCs|j�|�dSr)r
  24  �update)rr2rrr
  25  r+szPlanner._update_context)�__name__�
  26  __module__�__qualname__rr)rr!rrr�tupler(rrrrrr
  27  rsrN)	�typingrrr�modules.llm.ollama_clientrZmodules.tools.tool_executorrrrrrr
  28  �<module>s