vectara-agentic 0.3.3__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vectara-agentic might be problematic. Click here for more details.

Files changed (56) hide show
  1. tests/__init__.py +7 -0
  2. tests/conftest.py +316 -0
  3. tests/endpoint.py +54 -17
  4. tests/run_tests.py +112 -0
  5. tests/test_agent.py +35 -33
  6. tests/test_agent_fallback_memory.py +270 -0
  7. tests/test_agent_memory_consistency.py +229 -0
  8. tests/test_agent_type.py +86 -143
  9. tests/test_api_endpoint.py +4 -0
  10. tests/test_bedrock.py +50 -31
  11. tests/test_fallback.py +4 -0
  12. tests/test_gemini.py +27 -59
  13. tests/test_groq.py +50 -31
  14. tests/test_private_llm.py +11 -2
  15. tests/test_return_direct.py +6 -2
  16. tests/test_serialization.py +7 -6
  17. tests/test_session_memory.py +252 -0
  18. tests/test_streaming.py +109 -0
  19. tests/test_together.py +62 -0
  20. tests/test_tools.py +10 -82
  21. tests/test_vectara_llms.py +4 -0
  22. tests/test_vhc.py +67 -0
  23. tests/test_workflow.py +13 -28
  24. vectara_agentic/__init__.py +27 -4
  25. vectara_agentic/_callback.py +65 -67
  26. vectara_agentic/_observability.py +30 -30
  27. vectara_agentic/_version.py +1 -1
  28. vectara_agentic/agent.py +565 -859
  29. vectara_agentic/agent_config.py +15 -14
  30. vectara_agentic/agent_core/__init__.py +22 -0
  31. vectara_agentic/agent_core/factory.py +383 -0
  32. vectara_agentic/{_prompts.py → agent_core/prompts.py} +21 -46
  33. vectara_agentic/agent_core/serialization.py +348 -0
  34. vectara_agentic/agent_core/streaming.py +483 -0
  35. vectara_agentic/agent_core/utils/__init__.py +29 -0
  36. vectara_agentic/agent_core/utils/hallucination.py +157 -0
  37. vectara_agentic/agent_core/utils/logging.py +52 -0
  38. vectara_agentic/agent_core/utils/schemas.py +87 -0
  39. vectara_agentic/agent_core/utils/tools.py +125 -0
  40. vectara_agentic/agent_endpoint.py +4 -6
  41. vectara_agentic/db_tools.py +37 -12
  42. vectara_agentic/llm_utils.py +42 -43
  43. vectara_agentic/sub_query_workflow.py +9 -14
  44. vectara_agentic/tool_utils.py +138 -83
  45. vectara_agentic/tools.py +36 -21
  46. vectara_agentic/tools_catalog.py +16 -16
  47. vectara_agentic/types.py +106 -8
  48. {vectara_agentic-0.3.3.dist-info → vectara_agentic-0.4.1.dist-info}/METADATA +111 -31
  49. vectara_agentic-0.4.1.dist-info/RECORD +53 -0
  50. tests/test_agent_planning.py +0 -64
  51. tests/test_hhem.py +0 -100
  52. vectara_agentic/hhem.py +0 -82
  53. vectara_agentic-0.3.3.dist-info/RECORD +0 -39
  54. {vectara_agentic-0.3.3.dist-info → vectara_agentic-0.4.1.dist-info}/WHEEL +0 -0
  55. {vectara_agentic-0.3.3.dist-info → vectara_agentic-0.4.1.dist-info}/licenses/LICENSE +0 -0
  56. {vectara_agentic-0.3.3.dist-info → vectara_agentic-0.4.1.dist-info}/top_level.txt +0 -0
tests/test_agent_type.py CHANGED
@@ -1,198 +1,141 @@
1
- import unittest
2
-
3
- from vectara_agentic.agent import Agent, AgentType
4
- from vectara_agentic.agent_config import AgentConfig
5
- from vectara_agentic.tools import ToolsFactory
6
- from vectara_agentic.types import ModelProvider
7
-
8
- import nest_asyncio
9
- nest_asyncio.apply()
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
10
3
 
11
- def mult(x: float, y: float) -> float:
12
- "Multiply two numbers"
13
- return x * y
14
-
15
-
16
- react_config_anthropic = AgentConfig(
17
- agent_type=AgentType.REACT,
18
- main_llm_provider=ModelProvider.ANTHROPIC,
19
- tool_llm_provider=ModelProvider.ANTHROPIC,
20
- )
21
-
22
- # React with Google does not work with Gemini 2.5-flash
23
- react_config_gemini = AgentConfig(
24
- agent_type=AgentType.REACT,
25
- main_llm_provider=ModelProvider.GEMINI,
26
- main_llm_model_name="models/gemini-2.0-flash",
27
- tool_llm_provider=ModelProvider.GEMINI,
28
- tool_llm_model_name="models/gemini-2.0-flash",
29
- )
30
-
31
- react_config_together = AgentConfig(
32
- agent_type=AgentType.REACT,
33
- main_llm_provider=ModelProvider.TOGETHER,
34
- tool_llm_provider=ModelProvider.TOGETHER,
35
- )
36
-
37
- react_config_groq = AgentConfig(
38
- agent_type=AgentType.REACT,
39
- main_llm_provider=ModelProvider.GROQ,
40
- tool_llm_provider=ModelProvider.GROQ,
41
- )
4
+ warnings.simplefilter("ignore", DeprecationWarning)
42
5
 
43
- fc_config_anthropic = AgentConfig(
44
- agent_type=AgentType.FUNCTION_CALLING,
45
- main_llm_provider=ModelProvider.ANTHROPIC,
46
- tool_llm_provider=ModelProvider.ANTHROPIC,
47
- )
48
-
49
- fc_config_gemini = AgentConfig(
50
- agent_type=AgentType.FUNCTION_CALLING,
51
- main_llm_provider=ModelProvider.GEMINI,
52
- tool_llm_provider=ModelProvider.GEMINI,
53
- )
54
-
55
- fc_config_together = AgentConfig(
56
- agent_type=AgentType.FUNCTION_CALLING,
57
- main_llm_provider=ModelProvider.TOGETHER,
58
- tool_llm_provider=ModelProvider.TOGETHER,
59
- )
6
+ import unittest
60
7
 
61
- fc_config_groq = AgentConfig(
62
- agent_type=AgentType.FUNCTION_CALLING,
63
- main_llm_provider=ModelProvider.GROQ,
64
- tool_llm_provider=ModelProvider.GROQ,
8
+ import sys
9
+ import os
10
+ sys.path.insert(0, os.path.dirname(__file__))
11
+
12
+ from conftest import (
13
+ AgentTestMixin,
14
+ mult,
15
+ STANDARD_TEST_TOPIC,
16
+ STANDARD_TEST_INSTRUCTIONS,
17
+ default_config,
18
+ react_config_anthropic,
19
+ react_config_gemini,
20
+ react_config_together,
21
+ fc_config_anthropic,
22
+ fc_config_gemini,
23
+ fc_config_together,
65
24
  )
25
+ from vectara_agentic.agent import Agent
26
+ from vectara_agentic.tools import ToolsFactory
66
27
 
28
+ class TestAgentType(unittest.TestCase, AgentTestMixin):
67
29
 
68
- openai_config = AgentConfig(
69
- agent_type=AgentType.OPENAI,
70
- )
71
-
72
- class TestAgentType(unittest.TestCase):
30
+ def setUp(self):
31
+ self.tools = [ToolsFactory().create_tool(mult)]
32
+ self.topic = STANDARD_TEST_TOPIC
33
+ self.instructions = STANDARD_TEST_INSTRUCTIONS
73
34
 
74
- def test_openai(self):
75
- tools = [ToolsFactory().create_tool(mult)]
76
- topic = "AI topic"
77
- instructions = "Always do as your father tells you, if your mother agrees!"
35
+ def test_default_function_calling(self):
78
36
  agent = Agent(
79
- agent_config=openai_config,
80
- tools=tools,
81
- topic=topic,
82
- custom_instructions=instructions,
37
+ agent_config=default_config,
38
+ tools=self.tools,
39
+ topic=self.topic,
40
+ custom_instructions=self.instructions,
83
41
  )
84
42
 
85
43
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
86
44
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
87
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
45
+ res = agent.chat(
46
+ "multiply the results of the last two multiplications. Only give the answer, nothing else."
47
+ )
88
48
  self.assertIn("1050", res.response)
89
49
 
90
50
  def test_gemini(self):
91
- tools = [ToolsFactory().create_tool(mult)]
92
- topic = "AI topic"
93
- instructions = "Always do as your father tells you, if your mother agrees!"
94
-
95
51
  agent = Agent(
96
52
  agent_config=react_config_gemini,
97
- tools=tools,
98
- topic=topic,
99
- custom_instructions=instructions,
53
+ tools=self.tools,
54
+ topic=self.topic,
55
+ custom_instructions=self.instructions,
100
56
  )
101
57
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
102
58
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
103
- res = agent.chat("what is the result of multiplying the results of the last two multiplications. Only give the answer, nothing else.")
59
+ res = agent.chat(
60
+ "what is the result of multiplying the results of the last two "
61
+ "multiplications. Only give the answer, nothing else."
62
+ )
104
63
  self.assertIn("1050", res.response)
105
64
 
106
65
  agent = Agent(
107
66
  agent_config=fc_config_gemini,
108
- tools=tools,
109
- topic=topic,
110
- custom_instructions=instructions,
67
+ tools=self.tools,
68
+ topic=self.topic,
69
+ custom_instructions=self.instructions,
111
70
  )
112
71
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
113
72
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
114
- res = agent.chat("what is the result of multiplying the results of the last two multiplications. Only give the answer, nothing else.")
73
+ res = agent.chat(
74
+ "what is the result of multiplying the results of the last two "
75
+ "multiplications. Only give the answer, nothing else."
76
+ )
115
77
  self.assertIn("1050", res.response)
116
78
 
117
79
  def test_together(self):
118
- tools = [ToolsFactory().create_tool(mult)]
119
- topic = "AI topic"
120
- instructions = "Always do as your father tells you, if your mother agrees!"
121
-
80
+ # Test ReAct agent with Together
122
81
  agent = Agent(
123
82
  agent_config=react_config_together,
124
- tools=tools,
125
- topic=topic,
126
- custom_instructions=instructions,
127
- )
128
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
129
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
130
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
131
- self.assertIn("1050", res.response)
132
-
133
- agent = Agent(
134
- agent_config=fc_config_together,
135
- tools=tools,
136
- topic=topic,
137
- custom_instructions=instructions,
83
+ tools=self.tools,
84
+ topic=self.topic,
85
+ custom_instructions=self.instructions,
138
86
  )
139
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
140
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
141
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
142
- self.assertIn("1050", res.response)
143
87
 
144
- def test_groq(self):
145
- tools = [ToolsFactory().create_tool(mult)]
146
- topic = "AI topic"
147
- instructions = "Always do as your father tells you, if your mother agrees!"
88
+ with self.with_provider_fallback("Together AI"):
89
+ agent.chat("What is 5 times 10. Only give the answer, nothing else")
90
+ agent.chat("what is 3 times 7. Only give the answer, nothing else")
91
+ res = agent.chat(
92
+ "multiply the results of the last two multiplications. Only give the answer, nothing else."
93
+ )
94
+ self.check_response_and_skip(res, "Together AI")
95
+ self.assertIn("1050", res.response)
148
96
 
97
+ # Test Function Calling agent with Together
149
98
  agent = Agent(
150
- agent_config=react_config_groq,
151
- tools=tools,
152
- topic=topic,
153
- custom_instructions=instructions,
99
+ agent_config=fc_config_together,
100
+ tools=self.tools,
101
+ topic=self.topic,
102
+ custom_instructions=self.instructions,
154
103
  )
155
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
156
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
157
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
158
- self.assertIn("1050", res.response)
159
104
 
160
- agent = Agent(
161
- agent_config=fc_config_groq,
162
- tools=tools,
163
- topic=topic,
164
- custom_instructions=instructions,
165
- )
166
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
167
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
168
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
169
- self.assertIn("1050", res.response)
105
+ with self.with_provider_fallback("Together AI"):
106
+ agent.chat("What is 5 times 10. Only give the answer, nothing else")
107
+ agent.chat("what is 3 times 7. Only give the answer, nothing else")
108
+ res = agent.chat(
109
+ "multiply the results of the last two multiplications. Only give the answer, nothing else."
110
+ )
111
+ self.check_response_and_skip(res, "Together AI")
112
+ self.assertIn("1050", res.response)
170
113
 
171
114
  def test_anthropic(self):
172
- tools = [ToolsFactory().create_tool(mult)]
173
- topic = "AI topic"
174
- instructions = "Always do as your father tells you, if your mother agrees!"
175
-
176
115
  agent = Agent(
177
116
  agent_config=react_config_anthropic,
178
- tools=tools,
179
- topic=topic,
180
- custom_instructions=instructions,
117
+ tools=self.tools,
118
+ topic=self.topic,
119
+ custom_instructions=self.instructions,
181
120
  )
182
121
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
183
122
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
184
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
123
+ res = agent.chat(
124
+ "multiply the results of the last two multiplications. Only give the answer, nothing else."
125
+ )
185
126
  self.assertIn("1050", res.response)
186
127
 
187
128
  agent = Agent(
188
129
  agent_config=fc_config_anthropic,
189
- tools=tools,
190
- topic=topic,
191
- custom_instructions=instructions,
130
+ tools=self.tools,
131
+ topic=self.topic,
132
+ custom_instructions=self.instructions,
192
133
  )
193
134
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
194
135
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
195
- res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
136
+ res = agent.chat(
137
+ "multiply the results of the last two multiplications. Only give the answer, nothing else."
138
+ )
196
139
  self.assertIn("1050", res.response)
197
140
 
198
141
 
@@ -1,3 +1,7 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import unittest
2
6
  from uuid import UUID
3
7
 
tests/test_bedrock.py CHANGED
@@ -1,41 +1,60 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import unittest
6
+ import threading
2
7
 
3
- from vectara_agentic.agent import Agent, AgentType
4
- from vectara_agentic.agent_config import AgentConfig
8
+ from vectara_agentic.agent import Agent
5
9
  from vectara_agentic.tools import ToolsFactory
6
- from vectara_agentic.types import ModelProvider
7
10
 
8
11
  import nest_asyncio
9
12
  nest_asyncio.apply()
10
13
 
11
-
12
- def mult(x: float, y: float) -> float:
13
- "Multiply two numbers"
14
- return x * y
15
-
16
-
17
- fc_config_bedrock = AgentConfig(
18
- agent_type=AgentType.FUNCTION_CALLING,
19
- main_llm_provider=ModelProvider.BEDROCK,
20
- tool_llm_provider=ModelProvider.BEDROCK,
21
- )
22
-
23
- class TestBedrock(unittest.TestCase):
24
-
25
- def test_multiturn(self):
26
- tools = [ToolsFactory().create_tool(mult)]
27
- topic = "AI topic"
28
- instructions = "Always do as your father tells you, if your mother agrees!"
29
- agent = Agent(
30
- tools=tools,
31
- topic=topic,
32
- custom_instructions=instructions,
33
- )
34
-
35
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
36
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
37
- res = agent.chat("multiply the results of the last two questions. Output only the answer.")
38
- self.assertEqual(res.response, "1050")
14
+ from conftest import mult, fc_config_bedrock, STANDARD_TEST_TOPIC, STANDARD_TEST_INSTRUCTIONS
15
+
16
+ ARIZE_LOCK = threading.Lock()
17
+
18
+ class TestBedrock(unittest.IsolatedAsyncioTestCase):
19
+
20
+ async def test_multiturn(self):
21
+ with ARIZE_LOCK:
22
+ tools = [ToolsFactory().create_tool(mult)]
23
+ agent = Agent(
24
+ tools=tools,
25
+ topic=STANDARD_TEST_TOPIC,
26
+ custom_instructions=STANDARD_TEST_INSTRUCTIONS,
27
+ agent_config=fc_config_bedrock,
28
+ )
29
+
30
+ # First calculation: 5 * 10 = 50
31
+ stream1 = await agent.astream_chat(
32
+ "What is 5 times 10. Only give the answer, nothing else"
33
+ )
34
+ # Consume the stream
35
+ async for chunk in stream1.async_response_gen():
36
+ pass
37
+ _ = await stream1.aget_response()
38
+
39
+ # Second calculation: 3 * 7 = 21
40
+ stream2 = await agent.astream_chat(
41
+ "what is 3 times 7. Only give the answer, nothing else"
42
+ )
43
+ # Consume the stream
44
+ async for chunk in stream2.async_response_gen():
45
+ pass
46
+ _ = await stream2.aget_response()
47
+
48
+ # Final calculation: 50 * 21 = 1050
49
+ stream3 = await agent.astream_chat(
50
+ "multiply the results of the last two questions. Output only the answer."
51
+ )
52
+ # Consume the stream
53
+ async for chunk in stream3.async_response_gen():
54
+ pass
55
+ response3 = await stream3.aget_response()
56
+
57
+ self.assertEqual(response3.response, "1050")
39
58
 
40
59
 
41
60
  if __name__ == "__main__":
tests/test_fallback.py CHANGED
@@ -1,3 +1,7 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import os
2
6
  import unittest
3
7
  import subprocess
tests/test_gemini.py CHANGED
@@ -1,16 +1,18 @@
1
- import unittest
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
2
4
 
3
- from pydantic import Field, BaseModel
5
+ import unittest
4
6
 
5
- from vectara_agentic.agent import Agent, AgentType
6
- from vectara_agentic.agent_config import AgentConfig
7
- from vectara_agentic.tools import VectaraToolFactory
8
- from vectara_agentic.types import ModelProvider
7
+ from vectara_agentic.agent import Agent
8
+ from vectara_agentic.tools import ToolsFactory
9
9
 
10
10
 
11
11
  import nest_asyncio
12
12
  nest_asyncio.apply()
13
13
 
14
+ from conftest import mult, fc_config_gemini, STANDARD_TEST_TOPIC, STANDARD_TEST_INSTRUCTIONS
15
+
14
16
  tickers = {
15
17
  "C": "Citigroup",
16
18
  "COF": "Capital One",
@@ -32,11 +34,6 @@ tickers = {
32
34
  years = list(range(2015, 2025))
33
35
 
34
36
 
35
- def mult(x: float, y: float) -> float:
36
- "Multiply two numbers"
37
- return x * y
38
-
39
-
40
37
  def get_company_info() -> list[str]:
41
38
  """
42
39
  Returns a dictionary of companies you can query about. Always check this before using any other tool.
@@ -54,61 +51,32 @@ def get_valid_years() -> list[str]:
54
51
  return years
55
52
 
56
53
 
57
- fc_config_gemini = AgentConfig(
58
- agent_type=AgentType.FUNCTION_CALLING,
59
- main_llm_provider=ModelProvider.GEMINI,
60
- tool_llm_provider=ModelProvider.GEMINI,
61
- )
62
-
63
-
64
54
  class TestGEMINI(unittest.TestCase):
55
+ def test_gemini(self):
56
+ tools = [ToolsFactory().create_tool(mult)]
65
57
 
66
- def test_tool_with_many_arguments(self):
67
-
68
- vectara_corpus_key = "vectara-docs_1"
69
- vectara_api_key = "zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA"
70
- vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
71
-
72
- class QueryToolArgs(BaseModel):
73
- arg1: str = Field(description="the first argument", examples=["val1"])
74
- arg2: str = Field(description="the second argument", examples=["val2"])
75
- arg3: str = Field(description="the third argument", examples=["val3"])
76
- arg4: str = Field(description="the fourth argument", examples=["val4"])
77
- arg5: str = Field(description="the fifth argument", examples=["val5"])
78
- arg6: str = Field(description="the sixth argument", examples=["val6"])
79
- arg7: str = Field(description="the seventh argument", examples=["val7"])
80
- arg8: str = Field(description="the eighth argument", examples=["val8"])
81
- arg9: str = Field(description="the ninth argument", examples=["val9"])
82
- arg10: str = Field(description="the tenth argument", examples=["val10"])
83
- arg11: str = Field(description="the eleventh argument", examples=["val11"])
84
- arg12: str = Field(description="the twelfth argument", examples=["val12"])
85
- arg13: str = Field(
86
- description="the thirteenth argument", examples=["val13"]
87
- )
88
- arg14: str = Field(
89
- description="the fourteenth argument", examples=["val14"]
90
- )
91
- arg15: str = Field(description="the fifteenth argument", examples=["val15"])
92
-
93
- query_tool_1 = vec_factory.create_rag_tool(
94
- tool_name="rag_tool",
95
- tool_description="""
96
- A dummy tool that takes 15 arguments and returns a response (str) to the user query based on the data in this corpus.
97
- We are using this tool to test the tool factory works and does not crash with OpenAI.
98
- """,
99
- tool_args_schema=QueryToolArgs,
58
+ agent = Agent(
59
+ agent_config=fc_config_gemini,
60
+ tools=tools,
61
+ topic=STANDARD_TEST_TOPIC,
62
+ custom_instructions=STANDARD_TEST_INSTRUCTIONS,
100
63
  )
64
+ _ = agent.chat("What is 5 times 10. Only give the answer, nothing else")
65
+ _ = agent.chat("what is 3 times 7. Only give the answer, nothing else")
66
+ res = agent.chat("what is the result of multiplying the results of the last two multiplications. Only give the answer, nothing else.")
67
+ self.assertIn("1050", res.response)
68
+
69
+ def test_gemini_single_prompt(self):
70
+ tools = [ToolsFactory().create_tool(mult)]
101
71
 
102
72
  agent = Agent(
103
- tools=[query_tool_1],
104
- topic="Sample topic",
105
- custom_instructions="Call the tool with 15 arguments",
106
73
  agent_config=fc_config_gemini,
74
+ tools=tools,
75
+ topic=STANDARD_TEST_TOPIC,
76
+ custom_instructions=STANDARD_TEST_INSTRUCTIONS,
107
77
  )
108
- res = agent.chat("What is the stock price?")
109
- self.assertTrue(
110
- any(sub in str(res) for sub in ["I don't know", "I do not have"])
111
- )
78
+ res = agent.chat("First, multiply 5 by 10. Then, multiply 3 by 7. Finally, multiply the results of the first two calculations.")
79
+ self.assertIn("1050", res.response)
112
80
 
113
81
 
114
82
  if __name__ == "__main__":
tests/test_groq.py CHANGED
@@ -1,41 +1,60 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import unittest
6
+ import threading
2
7
 
3
- from vectara_agentic.agent import Agent, AgentType
4
- from vectara_agentic.agent_config import AgentConfig
8
+ from vectara_agentic.agent import Agent
5
9
  from vectara_agentic.tools import ToolsFactory
6
- from vectara_agentic.types import ModelProvider
7
10
 
8
11
  import nest_asyncio
9
12
  nest_asyncio.apply()
10
13
 
11
- def mult(x: float, y: float) -> float:
12
- "Multiply two numbers"
13
- return x * y
14
-
15
-
16
- fc_config_groq = AgentConfig(
17
- agent_type=AgentType.FUNCTION_CALLING,
18
- main_llm_provider=ModelProvider.GROQ,
19
- tool_llm_provider=ModelProvider.GROQ,
20
- )
21
-
22
-
23
- class TestGROQ(unittest.TestCase):
24
-
25
- def test_multiturn(self):
26
- tools = [ToolsFactory().create_tool(mult)]
27
- topic = "AI topic"
28
- instructions = "Always do as your father tells you, if your mother agrees!"
29
- agent = Agent(
30
- tools=tools,
31
- topic=topic,
32
- custom_instructions=instructions,
33
- )
34
-
35
- agent.chat("What is 5 times 10. Only give the answer, nothing else")
36
- agent.chat("what is 3 times 7. Only give the answer, nothing else")
37
- res = agent.chat("multiply the results of the last two questions. Output only the answer.")
38
- self.assertEqual(res.response, "1050")
14
+ from conftest import mult, fc_config_groq, STANDARD_TEST_TOPIC, STANDARD_TEST_INSTRUCTIONS
15
+
16
+ ARIZE_LOCK = threading.Lock()
17
+
18
+ class TestGROQ(unittest.IsolatedAsyncioTestCase):
19
+
20
+ async def test_multiturn(self):
21
+ with ARIZE_LOCK:
22
+ tools = [ToolsFactory().create_tool(mult)]
23
+ agent = Agent(
24
+ tools=tools,
25
+ topic=STANDARD_TEST_TOPIC,
26
+ custom_instructions=STANDARD_TEST_INSTRUCTIONS,
27
+ agent_config=fc_config_groq,
28
+ )
29
+
30
+ # First calculation: 5 * 10 = 50
31
+ stream1 = await agent.astream_chat(
32
+ "What is 5 times 10. Only give the answer, nothing else"
33
+ )
34
+ # Consume the stream
35
+ async for chunk in stream1.async_response_gen():
36
+ pass
37
+ _ = await stream1.aget_response()
38
+
39
+ # Second calculation: 3 * 7 = 21
40
+ stream2 = await agent.astream_chat(
41
+ "what is 3 times 7. Only give the answer, nothing else"
42
+ )
43
+ # Consume the stream
44
+ async for chunk in stream2.async_response_gen():
45
+ pass
46
+ _ = await stream2.aget_response()
47
+
48
+ # Final calculation: 50 * 21 = 1050
49
+ stream3 = await agent.astream_chat(
50
+ "multiply the results of the last two questions. Output only the answer."
51
+ )
52
+ # Consume the stream
53
+ async for chunk in stream3.async_response_gen():
54
+ pass
55
+ response3 = await stream3.aget_response()
56
+
57
+ self.assertEqual(response3.response, "1050")
39
58
 
40
59
 
41
60
  if __name__ == "__main__":
tests/test_private_llm.py CHANGED
@@ -1,3 +1,7 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import os
2
6
  import unittest
3
7
  import subprocess
@@ -48,19 +52,24 @@ class TestPrivateLLM(unittest.TestCase):
48
52
  topic = "calculator"
49
53
  custom_instructions = "you are an agent specializing in math, assisting a user."
50
54
  config = AgentConfig(
51
- agent_type=AgentType.REACT,
55
+ agent_type=AgentType.FUNCTION_CALLING,
52
56
  main_llm_provider=ModelProvider.PRIVATE,
53
57
  main_llm_model_name="gpt-4.1",
54
58
  private_llm_api_base=f"http://127.0.0.1:{FLASK_PORT}/v1",
55
59
  private_llm_api_key="TEST_API_KEY",
56
60
  )
57
61
  agent = Agent(agent_config=config, tools=tools, topic=topic,
58
- custom_instructions=custom_instructions)
62
+ custom_instructions=custom_instructions, verbose=False)
59
63
 
60
64
  # To run this test, you must have OPENAI_API_KEY in your environment
61
65
  res = agent.chat(
62
66
  "What is 5 times 10. Only give the answer, nothing else."
63
67
  ).response
68
+ if res is None:
69
+ self.fail("Agent returned None response")
70
+ # Convert to string for comparison if it's a number
71
+ if isinstance(res, (int, float)):
72
+ res = str(int(res))
64
73
  self.assertEqual(res, "50")
65
74
 
66
75
 
@@ -1,3 +1,7 @@
1
+ # Suppress external dependency warnings before any other imports
2
+ import warnings
3
+ warnings.simplefilter("ignore", DeprecationWarning)
4
+
1
5
  import unittest
2
6
 
3
7
  from vectara_agentic.agent import Agent
@@ -26,7 +30,7 @@ class TestAgentPackage(unittest.TestCase):
26
30
  custom_instructions="You are a helpful assistant.",
27
31
  )
28
32
  res = agent.chat("What is Vectara?")
29
- self.assertIn("Vectara is an end-to-end platform designed", str(res))
33
+ self.assertIn("Vectara is an end-to-end platform", str(res))
30
34
 
31
35
  def test_from_corpus(self):
32
36
  agent = Agent.from_corpus(
@@ -38,7 +42,7 @@ class TestAgentPackage(unittest.TestCase):
38
42
  return_direct=True,
39
43
  )
40
44
  res = agent.chat("What is Vectara?")
41
- self.assertIn("Vectara is an end-to-end platform designed", str(res))
45
+ self.assertIn("Vectara is an end-to-end platform", str(res))
42
46
 
43
47
 
44
48
  if __name__ == "__main__":