diff --git a/.gitignore b/.gitignore index 37d20996..e66cd370 100644 --- a/.gitignore +++ b/.gitignore @@ -146,3 +146,4 @@ cython_debug/ # CAI files .cai/ .vscode/ +cai_env/ diff --git a/src/cai/prompts/core/system_master_template.md b/src/cai/prompts/core/system_master_template.md index b3ad0c1a..f2b25053 100644 --- a/src/cai/prompts/core/system_master_template.md +++ b/src/cai/prompts/core/system_master_template.md @@ -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 diff --git a/tests/test_agent_config.py b/tests/agents/test_agent_config.py similarity index 100% rename from tests/test_agent_config.py rename to tests/agents/test_agent_config.py diff --git a/tests/test_agent_hooks.py b/tests/agents/test_agent_hooks.py similarity index 100% rename from tests/test_agent_hooks.py rename to tests/agents/test_agent_hooks.py diff --git a/tests/test_agent_runner.py b/tests/agents/test_agent_runner.py similarity index 100% rename from tests/test_agent_runner.py rename to tests/agents/test_agent_runner.py diff --git a/tests/test_agent_runner_streamed.py b/tests/agents/test_agent_runner_streamed.py similarity index 100% rename from tests/test_agent_runner_streamed.py rename to tests/agents/test_agent_runner_streamed.py diff --git a/tests/agents/test_agent_system_master_template.py b/tests/agents/test_agent_system_master_template.py new file mode 100644 index 00000000..cb345760 --- /dev/null +++ b/tests/agents/test_agent_system_master_template.py @@ -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('') diff --git a/tests/test_agent_tracing.py b/tests/agents/test_agent_tracing.py similarity index 100% rename from tests/test_agent_tracing.py rename to tests/agents/test_agent_tracing.py diff --git a/tests/test_function_tool.py b/tests/agents/test_function_tool.py similarity index 100% rename from tests/test_function_tool.py rename to tests/agents/test_function_tool.py diff --git a/tests/test_function_tool_decorator.py b/tests/tools/test_function_tool_decorator.py similarity index 100% rename from tests/test_function_tool_decorator.py rename to tests/tools/test_function_tool_decorator.py diff --git a/tests/test_handoff_tool.py b/tests/tools/test_handoff_tool.py similarity index 100% rename from tests/test_handoff_tool.py rename to tests/tools/test_handoff_tool.py diff --git a/tests/test_tool_choice_reset.py b/tests/tools/test_tool_choice_reset.py similarity index 100% rename from tests/test_tool_choice_reset.py rename to tests/tools/test_tool_choice_reset.py diff --git a/tests/test_tool_converter.py b/tests/tools/test_tool_converter.py similarity index 100% rename from tests/test_tool_converter.py rename to tests/tools/test_tool_converter.py diff --git a/tests/test_tool_use_behavior.py b/tests/tools/test_tool_use_behavior.py similarity index 100% rename from tests/test_tool_use_behavior.py rename to tests/tools/test_tool_use_behavior.py diff --git a/tests/tracing/test_processor_api_key.py b/tests/tracing/test_processor_api_key.py index b0a0218a..98e36a2e 100644 --- a/tests/tracing/test_processor_api_key.py +++ b/tests/tracing/test_processor_api_key.py @@ -1,6 +1,6 @@ import pytest -from agents.tracing.processors import BackendSpanExporter +from cai.sdk.agents.tracing.processors import BackendSpanExporter @pytest.mark.asyncio diff --git a/tests/test_tracing.py b/tests/tracing/test_tracing.py similarity index 100% rename from tests/test_tracing.py rename to tests/tracing/test_tracing.py diff --git a/tests/test_tracing_errors.py b/tests/tracing/test_tracing_errors.py similarity index 100% rename from tests/test_tracing_errors.py rename to tests/tracing/test_tracing_errors.py diff --git a/tests/test_tracing_errors_streamed.py b/tests/tracing/test_tracing_errors_streamed.py similarity index 100% rename from tests/test_tracing_errors_streamed.py rename to tests/tracing/test_tracing_errors_streamed.py