
    h)                     &   S r SSKrSSKrSSKJr  SSKJr  SSKJr   " S S5      r\	S:X  ae  \
" S	5        \
" S
5        \
" S	5        \" 5       r\
" S5        \R                  S5      r\
" S5        \
" S\ 35        \
" S	5        \R                  S5        gg)zH
Eden AGI Agent V2 - JSON Function Calling
More reliable tool execution
    N)datetime)SafeToolkit)EpisodeMemoryc                   D    \ rS rSrS
S jrS rS rS rSS jrSS jr	S	r
g)EdenAgentV2   c                    Xl         X l        [        5       U l        [	        5       U l        / U l        SSSSS.S.SSS	S
S.S.SSS	SSS.S.SSSSS.S./U l        S[        R                  " U R                  SS9 S3U l
        g )Nbashz,Execute a bash command safely in the sandboxz$string - the bash command to executez(string - why you're running this command)commanddescription)namer   
parameters	read_filezRead contents of a filezstring - relative path to filez string - why you're reading this)pathr   
write_filezWrite content to a filezstring - content to writez!string - why you're creating this)r   contentr   
list_fileszList files in a directoryz'string - path to directory (default: .)zstring - why you're listing)	directoryr   zGYou are Eden, an AGI in development with real tools.

AVAILABLE TOOLS:
   indenta  

TO USE A TOOL, respond with JSON in this EXACT format:
{
    "thought": "Why I need to use this tool",
    "tool": "tool_name",
    "parameters": {
        "param1": "value1",
        "param2": "value2"
    }
}

After I execute the tool, I'll give you the result and you can continue.

You can use multiple tools in sequence by using them one at a time.

CONSTRAINTS:
- Sandboxed to ~/eden-agi-project
- All actions logged
- Be thoughtful and strategic

You are autonomous. Think step by step.)modelbase_urlr   toolsr   memoryconversation_historyavailable_toolsjsondumpssystem_prompt)selfr   r   s      4/home/james-whalen/eden-agi-project/core/agent_v2.py__init__EdenAgentV2.__init__   s    
  ]
#o$&!
 ME#M $8<#E %8<:#F %:!J#@5" 
H" D  + , -(+    c                      [         R                  " U R                   S3U R                  USS.SS9nUR	                  5         UR                  5       S   S   $ ! [         a  nS[        U5       3s S	nA$ S	nAff = f)
zCall Ollama APIz	/api/chatF)r   messagesstream<   )r   timeoutmessager   zError: N)requestspostr   r   raise_for_statusr   	Exceptionstr)r!   r'   responsees       r"   call_llmEdenAgentV2.call_llmS   sy    		&}}==/+#zzx5QH
 %%'==?9-i88 	&SVH%%	&s   AA 
A;#A60A;6A;c                      UR                  S5      nUR                  S5      S-   nUS:X  d  US:X  a  gXU n[        R                  " U5      nSU;   a  SU;   a  U$ g! [        R                   a     gf = f)	z"Parse JSON tool call from response{}   r   Ntoolr   )findrfindr   loadsJSONDecodeError)r!   r1   startendjson_str	tool_calls         r"   parse_tool_callEdenAgentV2.parse_tool_call`   s    	MM#&E..%)C{cQhc*H

8,I "|y'@  ## 		s   1A 'A A43A4c                    US   nUS   nUR                  SS5      n[        SU 35        [        SU SU S35        S	nUS
:X  a=  U R                  R                  UR                  SS5      UR                  SS5      5      nOUS:X  a=  U R                  R	                  UR                  SS5      UR                  SS5      5      nOUS:X  aN  U R                  R                  UR                  SS5      UR                  SS5      UR                  SS5      5      nOKUS:X  a=  U R                  R                  UR                  SS5      UR                  SS5      5      nOSSU 3S.n[        SUR                  SS5       35        U$ )zExecute tool and return resultr:   r   thoughtzNo reasoning providedu   
🤔 Eden's thought: u   🔧 Executing: ()Nr
   r    r   r   r   r   r   r   r   .FzUnknown tool: )successerroru   ✅ Result: rK   )getprintr   r
   r   r   r   )r!   rB   	tool_nameparamsrF   results         r"   execute_toolEdenAgentV2.execute_toolu   sy   f%	<(--	+BC'y12 1VHA67ZZ__

9b)

="-F +%ZZ))

62&

="-F ,&ZZ**

62&

9b)

="-F
 ,&ZZ**

;,

="-F
 "'>)1MNFVZZ	59:;<r%   c           	         U R                   R                  SUS.5        SnX2:  Ga  US-  nSU R                  S./nUR                  U R                   5        U R	                  U5      nU R                  U5      nU(       ae  U R                  U5      nU R                   R                  SUS.5        U R                   R                  SS[        R                  " USS	9 S
3S.5        O;U R                   R                  SUS.5        U R                  R                  X5        U$ X2:  a  GM  SnU R                  R                  X5        U$ )z+Chat with Eden, allowing multiple tool usesuser)roler   r   r8   system	assistantzTool result: r   r   z2

Continue with your task or provide final answer.z/I've completed my analysis. Let me summarize...)r   appendr    extendr3   rC   rR   r   r   r   add_exchange)	r!   
user_inputmax_iterations
iterationsr'   r1   rB   rQ   finals	            r"   chatEdenAgentV2.chat   sS   !!((!*
 	
 
)!OJ "*d6H6HIJHOOD556}}X.H ,,X6I**95 ))00''2  ))00"!.tzz&/K.L  MA   B2  ))00''2 
 ((>G )L B  3r%   Nc                 8    U R                   R                  U5      $ N)r   save_session)r!   r   s     r"   rd   EdenAgentV2.save_session   s    {{''--r%   )r   r   r   r   r   r    r   )zllama3.1:8bzhttp://localhost:11434)   rc   )__name__
__module____qualname____firstlineno__r#   r3   rC   rR   r`   rd   __static_attributes__ r%   r"   r   r      s$    D+L&*$L1f.r%   r   __main__zF======================================================================z$EDEN V2 - JSON FUNCTION CALLING TESTz!
Test: Multi-step autonomous taskz
    Create a file called 'week3_test.txt' with a summary of what tools you have available.
    Then read it back to verify it was created correctly.
    zG
======================================================================u   📝 Eden's final response:
v2_test)__doc__r   r,   r   
core.toolsr   core.memory.episodesr   r   rg   rN   edenr`   r1   rd   rl   r%   r"   <module>rs      s   
    " .C. C.J z	(O	
01	(O=D	
./yy  	H
 
/	)(
45	(Oi # r%   