Skip to content

Commit

Permalink
add additional agent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty committed Feb 13, 2025
1 parent 3c63139 commit 74625bb
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions py/tests/integration/test_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from r2r import R2RClient


def test_agentic_citations_0(client: R2RClient, test_collection):

response = client.retrieval.rag(
query="Who was Aristotle? USE YOUR SOURCES.",
)
assert (
response.results.citations[0].document_id
== test_collection["document_ids"][0]
), "Expected first citation to first doc"


def test_agentic_citations_1(client: R2RClient, test_collection):

response = client.retrieval.rag(
query="Who was Socrates? USE YOUR SOURCES.",
)
assert (
response.results.citations[0].document_id
== test_collection["document_ids"][1]
), "Expected first citation to second doc"


def test_agentic_citations_2(client: R2RClient, test_collection):

response = client.retrieval.rag(
query="Who were Rene Descartes and Immanuel Kant? USE YOUR SOURCES.",
)
assert test_collection["document_ids"][2] in [
citation.document_id for citation in response.results.citations
], "Expected a citation to third doc"
assert test_collection["document_ids"][3] in [
citation.document_id for citation in response.results.citations
], "Expected a citation to fourth doc"


def test_agentic_citations_3(client: R2RClient, test_collection):
"""
Tests the agent endpoint in non-streaming mode with a single user message.
Verifies final text and citations.
"""
response = client.retrieval.agent(
message={
"role": "user",
"content": "Tell me about Socrates in detail. USE YOUR SOURCES.",
},
rag_generation_config={
"stream": False,
},
)
# Typically returns a WrappedAgentResponse
assert response.results.messages, "No messages returned"
assistant_msg = response.results.messages[-1]
assert "Socrates" in assistant_msg.content

print("response.results.messages = ", response.results.messages)
# If your server includes citations in `metadata`, you can check them here:
if assistant_msg.metadata and "citations" in assistant_msg.metadata:
citations = assistant_msg.metadata["citations"]
doc_ids = [c["document_id"] for c in citations]
assert (
test_collection["document_ids"][1] in doc_ids
), "Expected Socrates doc citation"

0 comments on commit 74625bb

Please sign in to comment.