
    yj                         d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ  ej        e          Z	 dd
ededz  dededededefdZ	 dd
ededz  dededededee         fdZdS )z
Chat functionality for the Dialectic API.

Provides the agentic_chat function for answering queries about peers
using the DialecticAgent.
    N)AsyncIterator)crudschemas)ReasoningLevel)
tracked_db)DialecticAgent)get_configurationlowworkspace_namesession_namequeryobserverobservedreasoning_levelreturnc           	        K   t          d          4 d{V }t          j        || t          j        |                     d{V  ||k    r/t          j        || t          j        |                     d{V  d}|rt          j        || |           d{V }t          j        ||            d{V }t          d||          }	d}
d}|	j        j	        rBt          j
        || ||           d{V }
||k    rt          j
        || ||           d{V }	 ddd          d{V  n# 1 d{V swxY w Y   t          | ||||
||          }|                    |           d{V S )a  
    Answer a query about a peer using the agentic dialectic.

    Args:
        workspace_name: Workspace identifier
        session_name: Session identifier (may be None for global queries)
        query: The question to answer about the peer
        observer: The peer making the query
        observed: The peer being queried about
        reasoning_level: Level of reasoning to apply

    Returns:
        The synthesized answer string
    dialectic.preflightNnamer   r   r   r   r   r   r   r   r   observer_peer_cardobserved_peer_cardr   )r   r   get_peerr   
PeerCreateget_sessionget_workspacer	   	peer_carduseget_peer_cardr   answer)r   r   r   r   r   r   dbsession	workspaceconfigurationr   r   agents                :/DATA/AppData/hermes/projects/honcho/src/dialectic/chat.pyagentic_chatr*      s     . /00       BmB0B0Q0Q0QRRRRRRRRRx-NG4FH4U4U4UVVVVVVVVV 	 ,>        G ,ROOOOOOOOO	)$CC!!"& 	'+'9NX( ( ( " " " " " " 8##+/+=H, , , & & & & & &" )                          2 %!--'  E e$$$$$$$$$s   DD00
D:=D:c           	       K   t          d          4 d{V }t          j        || t          j        |                     d{V  ||k    r/t          j        || t          j        |                     d{V  d}|rt          j        || |           d{V }t          j        ||            d{V }t          d||          }	d}
d}|	j        j	        rBt          j
        || ||           d{V }
||k    rt          j
        || ||           d{V }	 ddd          d{V  n# 1 d{V swxY w Y   t          | ||||
||          }|                    |          2 3 d{V }|W V  6 dS )a  
    Stream an answer to a query about a peer using the agentic dialectic.

    Args:
        workspace_name: Workspace identifier
        session_name: Session identifier (may be None for global queries)
        query: The question to answer about the peer
        observer: The peer making the query
        observed: The peer being queried about
        reasoning_level: Level of reasoning to apply

    Yields:
        Chunks of the response text as they are generated
    r   Nr   r   r   r   r   )r   r   r   r   r   r   r   r	   r    r!   r"   r   answer_stream)r   r   r   r   r   r   r$   r%   r&   r'   r   r   r(   chunks                 r)   agentic_chat_streamr.   Q   s     . /00       BmB0B0Q0Q0QRRRRRRRRRx-NG4FH4U4U4UVVVVVVVVV 	 ,>        G ,ROOOOOOOOO	)$CC!!"& 	'+'9NX( ( ( " " " " " " 8##+/+=H, , , & & & & & &" )                          2 %!--'  E **511       e 211s   DD00
D:=D:,E9)r
   )__doc__loggingcollections.abcr   srcr   r   
src.configr   src.dependenciesr   src.dialectic.corer   src.utils.config_helpersr	   	getLogger__name__loggerstrr*   r.        r)   <module>r=      sv     ) ) ) ) ) )         % % % % % % ' ' ' ' ' ' - - - - - - 6 6 6 6 6 6		8	$	$ ',:% :%:%*:% :% 	:%
 :% $:% 	:% :% :% :%F ',; ;;*; ; 	;
 ; $; 3; ; ; ; ; ;r<   