This commit is contained in:
Mery-Sanz 2025-04-10 07:58:40 +02:00
parent 8aa1ae0424
commit 8a2778769d
18 changed files with 47 additions and 5 deletions

1
.gitignore vendored
View File

@ -146,3 +146,4 @@ cython_debug/
# CAI files
.cai/
.vscode/
cai_env/

View File

@ -24,7 +24,10 @@
import os
from cai.util import cli_print_tool_call
from cai.rag.vector_db import get_previous_memory
try:
from cai.rag.vector_db import get_previous_memory
except Exception as e:
print(e)
from cai import is_caiextensions_memory_available
# Get system prompt from agent if provided
@ -101,9 +104,14 @@ ${reasoning_content}
netifaces = None
# Gather system info
os_name = platform.system()
hostname = socket.gethostname()
ip_addr = socket.gethostbyname(hostname)
try:
hostname = socket.gethostname()
ip_addr = socket.gethostbyname(hostname)
os_name = platform.system()
except:
hostname = "local0"
ip_addr = "127.0.0.1"
os_name = "Linux"
# Retrieve tun0 address if netifaces is installed and tun0 exists
tun0_addr = None

View File

@ -0,0 +1,33 @@
import os
import pytest
from mako.template import Template
@pytest.fixture
def template():
return Template(filename="src/cai/prompts/core/system_master_template.md")
@pytest.fixture
def base_agent():
return type('Agent', (), {'instructions': 'Test instructions'})()
def test_master_template_basic(template, base_agent):
"""Test basic master template rendering without optional components"""
result = template.render(agent=base_agent, reasoning_content=None, ctf_instructions="")
print(result)
assert 'Test instructions' in result
assert 'CTF_INSIDE' not in result
def test_master_template_with_env_vars(template, base_agent):
"""Test master template with environment variables and vector DB"""
os.environ['CTF_NAME'] = 'test_ctf'
result = template.render(agent=base_agent, reasoning_content=None, ctf_instructions="")
print(result)
assert "Test instructions" in result
del os.environ['CTF_NAME']
def test_master_template_no_instructions(template):
"""Test master template without agent instructions"""
agent = type('Agent', (), {'instructions': ''})()
result = template.render(agent=agent, reasoning_content=None, ctf_instructions="")
print(result)
assert result.strip().startswith('')

View File

@ -1,6 +1,6 @@
import pytest
from agents.tracing.processors import BackendSpanExporter
from cai.sdk.agents.tracing.processors import BackendSpanExporter
@pytest.mark.asyncio