o
    —hâ  ã                   @   s>   d dl mZmZmZ d dlmZ d dlmZ G dd„ dƒZdS )é    )ÚDictÚAnyÚList)Úquery_ollama)Úexecute_toolc                   @   s�   e Zd Zdd„ Zdeddfdd„Zdefdd	„Zd
edeeef fdd„Z	dede
fdd„Zdededdfdd„Zdeeef ddfdd„ZdS )ÚPlannerc                 C   s   g | _ i | _d S ©N)Úchat_historyÚcontext)Úself© r   ú:C:\Users\shubh\Videos\agent\agent\modules\agent\planner.pyÚ__init__   s   
zPlanner.__init__Ú
user_inputÚreturnNc                 C   s   | j d|d� d S )NÚuser©ÚroleÚcontent)Ú_update_history)r   r   r   r   r   Úreceive_input
   s   zPlanner.receive_inputc                 Ã   sh   �d}t |ƒD ]*}t| j| jdd�I d H }d|v r'|  |¡I d H }|  |¡ q| jd|d� |  S dS )Né   Úplanner)Úpromptr
   Ú
agent_typeú
[ToolCall:Ú	assistantr   z!Maximum processing cycles reached)Úranger   r	   r
   Ú_handle_tool_callÚ_update_contextr   )r   Z
max_cyclesÚ_Zllm_responseZtool_resultr   r   r   Úprocess   s   €ýzPlanner.processÚresponsec                 Ã   sR   �|  d¡d   d¡d  ¡ }|  |¡\}}t||ƒI d H }| jdt|ƒd� |S )Nr   é   Ú]r   Útoolr   )ÚsplitÚstripÚ_parse_tool_callr   r   Ústr)r   r"   Ú	tool_callZ	tool_nameÚargsÚresultr   r   r   r      s   €zPlanner._handle_tool_callr*   c                 C   s*   |  dd¡d t|  dd¡d  d¡ƒfS )Nú(r#   r   ú))r&   ÚevalÚrstrip)r   r*   r   r   r   r(   %   s   *zPlanner._parse_tool_callr   r   c                 C   s   | j  ||dœ¡ d S )Nr   )r	   Úappend)r   r   r   r   r   r   r   (   s   zPlanner._update_historyÚ	tool_datac                 C   s   | j  |¡ d S r   )r
   Úupdate)r   r2   r   r   r   r   +   s   zPlanner._update_context)Ú__name__Ú
__module__Ú__qualname__r   r)   r   r!   r   r   r   Útupler(   r   r   r   r   r   r   r      s    r   N)	Útypingr   r   r   Úmodules.llm.ollama_clientr   Zmodules.tools.tool_executorr   r   r   r   r   r   Ú<module>   s    