Skip to content

RDBC-998 Write tests for Python AI Agents#266

Merged
poissoncorp merged 3 commits intoravendb:v7.1from
poissoncorp:RDBC-998
Feb 27, 2026
Merged

RDBC-998 Write tests for Python AI Agents#266
poissoncorp merged 3 commits intoravendb:v7.1from
poissoncorp:RDBC-998

Conversation

@poissoncorp
Copy link
Contributor

RDBC-998 Write tests for Python AI Agents

Changes

ravendb/documents/operations/ai/agents/__init__.py

  • Exported AiAgentToolQueryOptions in the public API.

ravendb/tests/ai_agent_tests/test_ai_agents.py — 15 integration tests

CRUD operations against the real embedded test server.

Test What it covers
test_create_and_get_agent Create an agent, fetch it back, verify all fields round-trip
test_update_agent Update system prompt and verify the change persists
test_delete_agent Delete an agent, confirm it is gone
test_agent_with_query_tool Agent with a query tool; verify tool fields
test_agent_with_action_tool Agent with an action tool; verify tool fields
test_agent_with_multiple_tools Agent with both query and action tools
test_agent_with_parameters Agent with typed parameters and sample object
test_agent_connection_string_name Connection string name is stored and returned correctly
test_agent_system_prompt System prompt is stored and returned correctly
test_agent_identifier Agent identifier is stored and returned correctly
test_list_agents List all agents; verify the created agent appears
test_agent_with_query_tool_options_add_to_initial_context AiAgentToolQueryOptions.add_to_initial_context persists
test_agent_with_query_tool_options_allow_model_queries AiAgentToolQueryOptions.allow_model_queries persists
test_create_multiple_agents Create several agents; all appear in the list
test_delete_nonexistent_agent Deleting a non-existent agent raises an appropriate error

ravendb/tests/ai_agent_tests/test_ai_agents_conversation_mock.py — 21 hybrid tests

Agent CRUD runs against the real server; store.maintenance.send is patched so
RunConversationOperation calls return crafted ConversationResult objects — no
LLM API key required.

Group Test What it covers
Basic flow test_basic_conversation_returns_answer run() returns the mocked answer
test_conversation_id_and_change_vector_are_stored _conversation_id / _change_vector are updated after a call
test_usage_is_populated AiUsage fields (prompt/completion/total tokens) are propagated
test_elapsed_is_populated Elapsed time is set on the result
test_context_manager_usage AiConversation works as a context manager
Action handlers test_handle_invokes_handler_and_sends_response handle() callback is called with parsed args; response is sent back
test_receive_invokes_handler_with_request_and_args receive() callback receives both the raw request and parsed args
test_multi_turn_action_loop run() loops correctly across multiple ACTION_REQUIRED turns until DONE
Error strategies test_handler_error_send_to_model Handler exception with SEND_ERRORS_TO_MODEL — conversation continues
test_handler_error_raise_immediately Handler exception with RAISE_IMMEDIATELY — exception propagates
Unhandled actions test_on_unhandled_action_is_called on_unhandled_action callback fires; conversation continues after fallback response
test_no_handler_raises_runtime_error No handler and no on_unhandled_actionRuntimeError
Artificial actions test_add_artificial_action_with_response add_artificial_action_with_response() injects the action into the operation
test_add_artificial_action_validates_tool_id Empty/blank tool ID raises ValueError
test_add_artificial_action_validates_response_not_none None response raises ValueError
Creation options test_conversation_with_creation_options AiConversationCreationOptions (parameters, expiration) are forwarded to the operation
Streaming test_stream_collects_chunks_and_returns_answer stream() completes and returns a DONE result
Validation test_set_user_prompt_empty_raises Empty/blank prompt raises ValueError
test_required_actions_before_run_raises Accessing required_actions before run() raises RuntimeError
test_required_actions_after_run_returns_list required_actions returns an empty list after a DONE result
test_duplicate_action_handler_raises Registering two handlers for the same action name raises ValueError

@poissoncorp poissoncorp merged commit 70d7c62 into ravendb:v7.1 Feb 27, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant