CallbackEvals¶
CallbackEvals brings proper unit testing to your CXAS agent callbacks. It runs pytest-based tests against your callback Python code, either by reading it from a local app directory or by fetching it live from the CXAS API.
The main methods are:
test_all_callbacks_in_app_dir()— scans your local app directory, discovers everytest.pyalongside each callback'spython_code.py, and runs them all. Returns a DataFrame with results for each test.test_single_callback_for_agent()— fetches a specific agent's callback from the CXAS API and runs the test file you point it to. Useful for CI jobs where you want to verify a specific agent hasn't regressed.run_python_unit_tests_in_dir()— discovers and executes standalonetest_*.pyunit test files in a directory (such asevals/tool_tests/), supportingfilter_filesandexclude_filessubstring filtering. Automatically invoked byrun_all_evalswhen"callbacks"is included.
Both methods return a pandas DataFrame with columns: agent_name, callback_type, test_name, status, and error_message.
Quick Example¶
from cxas_scrapi import CallbackEvals
ce = CallbackEvals()
# Run all callback tests discovered in your local app directory
results_df = ce.test_all_callbacks_in_app_dir(
app_dir="./cxas_app/My_Agent_App",
)
print(results_df)
# Run tests for a specific agent and callback type (fetched from the API)
results_df = ce.test_single_callback_for_agent(
app_name="projects/my-project/locations/us/apps/my-app-id",
agent_name="root_agent",
callback_type="before_model_callback",
test_file_path="evals/callback_tests/tests/root_agent/before_model_callbacks/before_model/test.py",
)
print(results_df[["test_name", "status", "error_message"]])
Your test.py files look just like standard pytest:
import python_code # auto-injected by CallbackEvals
def test_callback_returns_correct_format():
result = python_code.before_model_callback(handler=None, request={"text": "hi"})
assert result is not None
Reference¶
CallbackEvals ¶
Provides methods for orchestrating and executing agent callback tests.
test_single_callback_for_agent ¶
test_single_callback_for_agent(app_name, agent_name, callback_type, test_file_path, log_file=None, pytest_args=None)
Runs test against a single callback fetched from the agent proto.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name | str | The CXAS App name. | required |
agent_name | str | The name or display name of the agent. | required |
callback_type | str | The type of callback (e.g., 'before_model', 'after_tool'). | required |
test_file_path | str | Path to the test.py file to run. | required |
log_file | str | None | Optional. Path to a file to log pytest output to. | None |
pytest_args | list[str] | None | Optional. Additional arguments to pass to pytest. | None |
Source code in src/cxas_scrapi/evals/callback_evals.py
test_all_callbacks_in_app_dir ¶
test_all_callbacks_in_app_dir(app_dir, agent_name='*', callback_type='*_callbacks', callback_name='*', log_file=None, pytest_args=None)
Runs pytest against all callback tests in the given agent directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_dir | str | The path to the CES app root directory. | required |
agent_name | str | Optional. The name of the agent to run tests for. If not provided, all agents will be tested. | '*' |
callback_type | str | Optional. The type of callback to run tests for. If not provided, all callback types will be tested. | '*_callbacks' |
callback_name | str | Optional. The name of the callback to run tests for. If not provided, all callbacks will be tested. | '*' |
log_file | str | None | Optional. Path to a file to log pytest output to. If not provided, output will be logged to the console. | None |
pytest_args | list[str] | None | Optional. Additional arguments to pass to pytest. Defaults to None. | None |
Returns:
| Type | Description |
|---|---|
DataFrame | A pandas DataFrame containing test execution results. |
Source code in src/cxas_scrapi/evals/callback_evals.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
run_python_unit_tests_in_dir ¶
Discovers and runs standalone test_*.py unit tests.
Source code in src/cxas_scrapi/evals/callback_evals.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |