vectara-agentic 0.2.6__py3-none-any.whl → 0.2.8__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.

tests/test_agent.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+ import threading
2
3
  from datetime import date
3
4
 
4
5
  from vectara_agentic.agent import _get_prompt, Agent, AgentType
@@ -6,9 +7,12 @@ from vectara_agentic.agent_config import AgentConfig
6
7
  from vectara_agentic.types import ModelProvider, ObserverType
7
8
  from vectara_agentic.tools import ToolsFactory
8
9
 
9
- def mult(x, y):
10
+ def mult(x: float, y: float) -> float:
10
11
  return x * y
11
12
 
13
+
14
+ ARIZE_LOCK = threading.Lock()
15
+
12
16
  class TestAgentPackage(unittest.TestCase):
13
17
  def test_get_prompt(self):
14
18
  prompt_template = "{chat_topic} on {today} with {custom_instructions}"
@@ -41,38 +45,39 @@ class TestAgentPackage(unittest.TestCase):
41
45
  )
42
46
 
43
47
  def test_agent_config(self):
44
- tools = [ToolsFactory().create_tool(mult)]
45
- topic = "AI topic"
46
- instructions = "Always do as your father tells you, if your mother agrees!"
47
- config = AgentConfig(
48
- agent_type=AgentType.REACT,
49
- main_llm_provider=ModelProvider.ANTHROPIC,
50
- main_llm_model_name="claude-3-5-sonnet-20241022",
51
- tool_llm_provider=ModelProvider.TOGETHER,
52
- tool_llm_model_name="meta-llama/Llama-3.3-70B-Instruct-Turbo",
53
- observer=ObserverType.ARIZE_PHOENIX
54
- )
55
-
56
- agent = Agent(
57
- tools=tools,
58
- topic=topic,
59
- custom_instructions=instructions,
60
- agent_config=config
61
- )
62
- self.assertEqual(agent._topic, topic)
63
- self.assertEqual(agent._custom_instructions, instructions)
64
- self.assertEqual(agent.agent_type, AgentType.REACT)
65
- self.assertEqual(agent.agent_config.observer, ObserverType.ARIZE_PHOENIX)
66
- self.assertEqual(agent.agent_config.main_llm_provider, ModelProvider.ANTHROPIC)
67
- self.assertEqual(agent.agent_config.tool_llm_provider, ModelProvider.TOGETHER)
68
-
69
- # To run this test, you must have ANTHROPIC_API_KEY and TOGETHER_API_KEY in your environment
70
- self.assertEqual(
71
- agent.chat(
72
- "What is 5 times 10. Only give the answer, nothing else"
73
- ).response.replace("$", "\\$"),
74
- "50",
75
- )
48
+ with ARIZE_LOCK:
49
+ tools = [ToolsFactory().create_tool(mult)]
50
+ topic = "AI topic"
51
+ instructions = "Always do as your father tells you, if your mother agrees!"
52
+ config = AgentConfig(
53
+ agent_type=AgentType.REACT,
54
+ main_llm_provider=ModelProvider.ANTHROPIC,
55
+ main_llm_model_name="claude-3-5-sonnet-20241022",
56
+ tool_llm_provider=ModelProvider.TOGETHER,
57
+ tool_llm_model_name="meta-llama/Llama-3.3-70B-Instruct-Turbo",
58
+ observer=ObserverType.ARIZE_PHOENIX
59
+ )
60
+
61
+ agent = Agent(
62
+ tools=tools,
63
+ topic=topic,
64
+ custom_instructions=instructions,
65
+ agent_config=config
66
+ )
67
+ self.assertEqual(agent._topic, topic)
68
+ self.assertEqual(agent._custom_instructions, instructions)
69
+ self.assertEqual(agent.agent_type, AgentType.REACT)
70
+ self.assertEqual(agent.agent_config.observer, ObserverType.ARIZE_PHOENIX)
71
+ self.assertEqual(agent.agent_config.main_llm_provider, ModelProvider.ANTHROPIC)
72
+ self.assertEqual(agent.agent_config.tool_llm_provider, ModelProvider.TOGETHER)
73
+
74
+ # To run this test, you must have ANTHROPIC_API_KEY and TOGETHER_API_KEY in your environment
75
+ self.assertEqual(
76
+ agent.chat(
77
+ "What is 5 times 10. Only give the answer, nothing else"
78
+ ).response.replace("$", "\\$"),
79
+ "50",
80
+ )
76
81
 
77
82
  def test_multiturn(self):
78
83
  tools = [ToolsFactory().create_tool(mult)]
@@ -101,44 +106,6 @@ class TestAgentPackage(unittest.TestCase):
101
106
  self.assertIsInstance(agent, Agent)
102
107
  self.assertEqual(agent._topic, "question answering")
103
108
 
104
- def test_serialization(self):
105
- config = AgentConfig(
106
- agent_type=AgentType.REACT,
107
- main_llm_provider=ModelProvider.ANTHROPIC,
108
- main_llm_model_name="claude-3-5-sonnet-20241022",
109
- tool_llm_provider=ModelProvider.TOGETHER,
110
- tool_llm_model_name="meta-llama/Llama-3.3-70B-Instruct-Turbo",
111
- observer=ObserverType.ARIZE_PHOENIX
112
- )
113
-
114
- agent = Agent.from_corpus(
115
- tool_name="RAG Tool",
116
- agent_config=config,
117
- vectara_corpus_key="corpus_key",
118
- vectara_api_key="api_key",
119
- data_description="information",
120
- assistant_specialty="question answering",
121
- )
122
-
123
- agent_reloaded = agent.loads(agent.dumps())
124
- agent_reloaded_again = agent_reloaded.loads(agent_reloaded.dumps())
125
-
126
- self.assertIsInstance(agent_reloaded, Agent)
127
- self.assertEqual(agent, agent_reloaded)
128
- self.assertEqual(agent.agent_type, agent_reloaded.agent_type)
129
-
130
- self.assertEqual(agent.agent_config.observer, agent_reloaded.agent_config.observer)
131
- self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded.agent_config.main_llm_provider)
132
- self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded.agent_config.tool_llm_provider)
133
-
134
- self.assertIsInstance(agent_reloaded, Agent)
135
- self.assertEqual(agent, agent_reloaded_again)
136
- self.assertEqual(agent.agent_type, agent_reloaded_again.agent_type)
137
-
138
- self.assertEqual(agent.agent_config.observer, agent_reloaded_again.agent_config.observer)
139
- self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded_again.agent_config.main_llm_provider)
140
- self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded_again.agent_config.tool_llm_provider)
141
-
142
109
  def test_chat_history(self):
143
110
  tools = [ToolsFactory().create_tool(mult)]
144
111
  topic = "AI topic"
@@ -1,45 +1,72 @@
1
1
  import unittest
2
2
 
3
- from vectara_agentic.agent import Agent
4
3
  from vectara_agentic.agent_config import AgentConfig
5
- from vectara_agentic.tools import ToolsFactory
4
+ from vectara_agentic.agent import Agent
5
+ from vectara_agentic.tools import VectaraToolFactory
6
+
7
+ from pydantic import Field, BaseModel
8
+
9
+
10
+ # SETUP speical test account credentials for vectara
11
+ # It's okay to expose these credentials in the test code
12
+ vectara_corpus_key = "vectara-docs_1"
13
+ vectara_api_key = 'zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA'
6
14
 
7
- def mult(x, y):
8
- return x * y
9
15
 
10
- def addition(x, y):
11
- return x + y
16
+ class QueryArgs(BaseModel):
17
+ query: str = Field(..., description="The user query, always in the form of a question.")
18
+
19
+
20
+ vec_factory = VectaraToolFactory(vectara_api_key=vectara_api_key,
21
+ vectara_corpus_key=vectara_corpus_key)
22
+ summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
23
+ ask_vectara = vec_factory.create_rag_tool(
24
+ tool_name = "ask_vectara",
25
+ tool_description = "This tool can respond to questions about Vectara.",
26
+ tool_args_schema = QueryArgs,
27
+ reranker = "multilingual_reranker_v1", rerank_k = 100, rerank_cutoff = 0.1,
28
+ n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
29
+ summary_num_results = 10,
30
+ vectara_summarizer = summarizer,
31
+ include_citations = True,
32
+ verbose=False,
33
+ )
12
34
 
13
35
  class TestAgentPlanningPackage(unittest.TestCase):
14
36
 
15
37
  def test_no_planning(self):
16
- tools = [ToolsFactory().create_tool(mult)]
17
- topic = "AI topic"
18
- instructions = "Always do as your father tells you, if your mother agrees!"
38
+ tools = [ask_vectara]
39
+ topic = "vectara"
40
+ instructions = "Answer user queries about Vectara."
41
+
42
+ query = "What is Vectara and what demos are available of the Vectara platform?"
19
43
  agent = Agent(
20
44
  tools=tools,
21
45
  topic=topic,
22
46
  custom_instructions=instructions,
23
- agent_config = AgentConfig()
47
+ agent_config=AgentConfig(),
24
48
  )
25
-
26
- res = agent.chat("If you multiply 5 times 7, then 3 times 2, and add the results - what do you get?")
27
- self.assertIn("41", res.response)
49
+ res = agent.chat(query)
50
+ self.assertIn("demos", res.response)
51
+ self.assertIn("Vectara", res.response)
28
52
 
29
53
  def test_structured_planning(self):
30
- tools = [ToolsFactory().create_tool(mult), ToolsFactory().create_tool(addition)]
31
- topic = "AI topic"
32
- instructions = "Always do as your father tells you, if your mother agrees!"
54
+ tools = [ask_vectara]
55
+ topic = "vectara"
56
+ instructions = "Answer user queries about Vectara."
57
+
58
+ query = "What is Vectara and what demos are available of the Vectara platform?"
33
59
  agent = Agent(
34
60
  tools=tools,
35
61
  topic=topic,
36
62
  custom_instructions=instructions,
37
- agent_config = AgentConfig(),
38
- use_structured_planning = True,
63
+ agent_config=AgentConfig(),
64
+ use_structured_planning=True,
39
65
  )
40
66
 
41
- res = agent.chat("If you multiply 5 times 7, then 3 times 2, and add the results - what do you get?")
42
- self.assertIn("41", res.response)
67
+ res = agent.chat(query)
68
+ self.assertIn("demos", res.response)
69
+ self.assertIn("Vectara", res.response)
43
70
 
44
71
 
45
72
  if __name__ == "__main__":
tests/test_agent_type.py CHANGED
@@ -7,24 +7,48 @@ from vectara_agentic.types import ModelProvider
7
7
 
8
8
  import nest_asyncio
9
9
  nest_asyncio.apply()
10
- def mult(x, y):
10
+
11
+ def mult(x: float, y: float) -> float:
11
12
  return x * y
12
13
 
13
14
 
14
- react_config_1 = AgentConfig(
15
+ react_config_anthropic = AgentConfig(
15
16
  agent_type=AgentType.REACT,
16
17
  main_llm_provider=ModelProvider.ANTHROPIC,
17
- main_llm_model_name="claude-3-7-sonnet-20250219",
18
- tool_llm_provider=ModelProvider.TOGETHER,
19
- tool_llm_model_name="meta-llama/Llama-3.3-70B-Instruct-Turbo",
18
+ tool_llm_provider=ModelProvider.ANTHROPIC,
19
+ )
20
+
21
+ react_config_gemini = AgentConfig(
22
+ agent_type=AgentType.REACT,
23
+ main_llm_provider=ModelProvider.GEMINI,
24
+ tool_llm_provider=ModelProvider.GEMINI,
20
25
  )
21
26
 
22
- react_config_2 = AgentConfig(
27
+ react_config_together = AgentConfig(
23
28
  agent_type=AgentType.REACT,
29
+ main_llm_provider=ModelProvider.TOGETHER,
30
+ tool_llm_provider=ModelProvider.TOGETHER,
31
+ )
32
+
33
+ fc_config_anthropic = AgentConfig(
34
+ agent_type=AgentType.FUNCTION_CALLING,
35
+ main_llm_provider=ModelProvider.ANTHROPIC,
36
+ tool_llm_provider=ModelProvider.ANTHROPIC,
37
+ )
38
+
39
+ fc_config_gemini = AgentConfig(
40
+ agent_type=AgentType.FUNCTION_CALLING,
24
41
  main_llm_provider=ModelProvider.GEMINI,
25
42
  tool_llm_provider=ModelProvider.GEMINI,
26
43
  )
27
44
 
45
+ fc_config_together = AgentConfig(
46
+ agent_type=AgentType.FUNCTION_CALLING,
47
+ main_llm_provider=ModelProvider.TOGETHER,
48
+ tool_llm_provider=ModelProvider.TOGETHER,
49
+ )
50
+
51
+
28
52
  openai_config = AgentConfig(
29
53
  agent_type=AgentType.OPENAI,
30
54
  )
@@ -47,28 +71,78 @@ class TestAgentType(unittest.TestCase):
47
71
  res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
48
72
  self.assertIn("1050", res.response)
49
73
 
50
- def test_react_anthropic(self):
74
+ def test_gemini(self):
75
+ tools = [ToolsFactory().create_tool(mult)]
76
+ topic = "AI topic"
77
+ instructions = "Always do as your father tells you, if your mother agrees!"
78
+
79
+ agent = Agent(
80
+ agent_config=react_config_gemini,
81
+ tools=tools,
82
+ topic=topic,
83
+ custom_instructions=instructions,
84
+ )
85
+ agent.chat("What is 5 times 10. Only give the answer, nothing else")
86
+ 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.")
88
+ self.assertIn("1050", res.response)
89
+
90
+ agent = Agent(
91
+ agent_config=fc_config_gemini,
92
+ tools=tools,
93
+ topic=topic,
94
+ custom_instructions=instructions,
95
+ )
96
+ agent.chat("What is 5 times 10. Only give the answer, nothing else")
97
+ agent.chat("what is 3 times 7. Only give the answer, nothing else")
98
+ res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
99
+ self.assertIn("1050", res.response)
100
+
101
+ def test_together(self):
51
102
  tools = [ToolsFactory().create_tool(mult)]
52
103
  topic = "AI topic"
53
104
  instructions = "Always do as your father tells you, if your mother agrees!"
105
+
54
106
  agent = Agent(
55
- agent_config=react_config_1,
107
+ agent_config=react_config_together,
56
108
  tools=tools,
57
109
  topic=topic,
58
110
  custom_instructions=instructions,
59
111
  )
112
+ agent.chat("What is 5 times 10. Only give the answer, nothing else")
113
+ agent.chat("what is 3 times 7. Only give the answer, nothing else")
114
+ res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
115
+ self.assertIn("1050", res.response)
60
116
 
117
+ agent = Agent(
118
+ agent_config=fc_config_together,
119
+ tools=tools,
120
+ topic=topic,
121
+ custom_instructions=instructions,
122
+ )
61
123
  agent.chat("What is 5 times 10. Only give the answer, nothing else")
62
124
  agent.chat("what is 3 times 7. Only give the answer, nothing else")
63
125
  res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
64
126
  self.assertIn("1050", res.response)
65
127
 
66
- def test_react_gemini(self):
128
+ def test_anthropic(self):
67
129
  tools = [ToolsFactory().create_tool(mult)]
68
130
  topic = "AI topic"
69
131
  instructions = "Always do as your father tells you, if your mother agrees!"
132
+
133
+ agent = Agent(
134
+ agent_config=react_config_anthropic,
135
+ tools=tools,
136
+ topic=topic,
137
+ custom_instructions=instructions,
138
+ )
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
+
70
144
  agent = Agent(
71
- agent_config=react_config_2,
145
+ agent_config=fc_config_anthropic,
72
146
  tools=tools,
73
147
  topic=topic,
74
148
  custom_instructions=instructions,
tests/test_fallback.py CHANGED
@@ -40,8 +40,8 @@ class TestFallback(unittest.TestCase):
40
40
  cls.flask_process.send_signal(signal.SIGINT)
41
41
  cls.flask_process.wait()
42
42
 
43
- def test_fallback(self):
44
- def mult(x, y):
43
+ def test_fallback_from_private(self):
44
+ def mult(x: float, y: float) -> float:
45
45
  return x * y
46
46
 
47
47
  tools = [ToolsFactory().create_tool(mult)]
tests/test_private_llm.py CHANGED
@@ -41,7 +41,7 @@ class TestPrivateLLM(unittest.TestCase):
41
41
  cls.flask_process.wait()
42
42
 
43
43
  def test_endpoint(self):
44
- def mult(x, y):
44
+ def mult(x: float, y: float) -> float:
45
45
  return x * y
46
46
 
47
47
  tools = [ToolsFactory().create_tool(mult)]
@@ -0,0 +1,110 @@
1
+ import unittest
2
+ import threading
3
+ import os
4
+
5
+ from vectara_agentic.agent import Agent, AgentType
6
+ from vectara_agentic.agent_config import AgentConfig
7
+ from vectara_agentic.types import ModelProvider, ObserverType
8
+ from vectara_agentic.tools import ToolsFactory
9
+
10
+ from llama_index.core.utilities.sql_wrapper import SQLDatabase
11
+ from sqlalchemy import create_engine
12
+
13
+ def mult(x: float, y: float) -> float:
14
+ return x * y
15
+
16
+
17
+ ARIZE_LOCK = threading.Lock()
18
+
19
+ class TestAgentSerialization(unittest.TestCase):
20
+
21
+ @classmethod
22
+ def tearDown(cls):
23
+ try:
24
+ os.remove('ev_database.db')
25
+ except FileNotFoundError:
26
+ pass
27
+
28
+ def test_serialization(self):
29
+ with ARIZE_LOCK:
30
+ config = AgentConfig(
31
+ agent_type=AgentType.REACT,
32
+ main_llm_provider=ModelProvider.ANTHROPIC,
33
+ tool_llm_provider=ModelProvider.TOGETHER,
34
+ observer=ObserverType.ARIZE_PHOENIX
35
+ )
36
+ db_tools = ToolsFactory().database_tools(
37
+ tool_name_prefix = "ev",
38
+ content_description = 'Electric Vehicles in the state of Washington and other population information',
39
+ sql_database = SQLDatabase(create_engine('sqlite:///ev_database.db')),
40
+ )
41
+
42
+ tools = [ToolsFactory().create_tool(mult)] + ToolsFactory().standard_tools() + db_tools
43
+ topic = "AI topic"
44
+ instructions = "Always do as your father tells you, if your mother agrees!"
45
+ agent = Agent(
46
+ tools=tools,
47
+ topic=topic,
48
+ custom_instructions=instructions,
49
+ agent_config=config
50
+ )
51
+
52
+ agent_reloaded = agent.loads(agent.dumps())
53
+ agent_reloaded_again = agent_reloaded.loads(agent_reloaded.dumps())
54
+
55
+ self.assertIsInstance(agent_reloaded, Agent)
56
+ self.assertEqual(agent, agent_reloaded)
57
+ self.assertEqual(agent.agent_type, agent_reloaded.agent_type)
58
+
59
+ self.assertEqual(agent.agent_config.observer, agent_reloaded.agent_config.observer)
60
+ self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded.agent_config.main_llm_provider)
61
+ self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded.agent_config.tool_llm_provider)
62
+
63
+ self.assertIsInstance(agent_reloaded, Agent)
64
+ self.assertEqual(agent, agent_reloaded_again)
65
+ self.assertEqual(agent.agent_type, agent_reloaded_again.agent_type)
66
+
67
+ self.assertEqual(agent.agent_config.observer, agent_reloaded_again.agent_config.observer)
68
+ self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded_again.agent_config.main_llm_provider)
69
+ self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded_again.agent_config.tool_llm_provider)
70
+
71
+ def test_serialization_from_corpus(self):
72
+ with ARIZE_LOCK:
73
+ config = AgentConfig(
74
+ agent_type=AgentType.REACT,
75
+ main_llm_provider=ModelProvider.ANTHROPIC,
76
+ tool_llm_provider=ModelProvider.TOGETHER,
77
+ observer=ObserverType.ARIZE_PHOENIX
78
+ )
79
+
80
+ agent = Agent.from_corpus(
81
+ tool_name="RAG Tool",
82
+ agent_config=config,
83
+ vectara_corpus_key="corpus_key",
84
+ vectara_api_key="api_key",
85
+ data_description="information",
86
+ assistant_specialty="question answering",
87
+ )
88
+
89
+ agent_reloaded = agent.loads(agent.dumps())
90
+ agent_reloaded_again = agent_reloaded.loads(agent_reloaded.dumps())
91
+
92
+ self.assertIsInstance(agent_reloaded, Agent)
93
+ self.assertEqual(agent, agent_reloaded)
94
+ self.assertEqual(agent.agent_type, agent_reloaded.agent_type)
95
+
96
+ self.assertEqual(agent.agent_config.observer, agent_reloaded.agent_config.observer)
97
+ self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded.agent_config.main_llm_provider)
98
+ self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded.agent_config.tool_llm_provider)
99
+
100
+ self.assertIsInstance(agent_reloaded, Agent)
101
+ self.assertEqual(agent, agent_reloaded_again)
102
+ self.assertEqual(agent.agent_type, agent_reloaded_again.agent_type)
103
+
104
+ self.assertEqual(agent.agent_config.observer, agent_reloaded_again.agent_config.observer)
105
+ self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded_again.agent_config.main_llm_provider)
106
+ self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded_again.agent_config.tool_llm_provider)
107
+
108
+
109
+ if __name__ == "__main__":
110
+ unittest.main()
tests/test_tools.py CHANGED
@@ -47,7 +47,7 @@ class TestToolsPackage(unittest.TestCase):
47
47
  self.assertEqual(search_tool.metadata.tool_type, ToolType.QUERY)
48
48
 
49
49
  def test_tool_factory(self):
50
- def mult(x, y):
50
+ def mult(x: float, y: float) -> float:
51
51
  return x * y
52
52
 
53
53
  tools_factory = ToolsFactory()
@@ -1,4 +1,4 @@
1
1
  """
2
2
  Define the version of the package.
3
3
  """
4
- __version__ = "0.2.6"
4
+ __version__ = "0.2.8"
vectara_agentic/agent.py CHANGED
@@ -21,7 +21,7 @@ from pydantic import Field, create_model, ValidationError
21
21
  from llama_index.core.memory import ChatMemoryBuffer
22
22
  from llama_index.core.llms import ChatMessage, MessageRole
23
23
  from llama_index.core.tools import FunctionTool
24
- from llama_index.core.agent import ReActAgent, StructuredPlannerAgent
24
+ from llama_index.core.agent import ReActAgent, StructuredPlannerAgent, FunctionCallingAgent
25
25
  from llama_index.core.agent.react.formatter import ReActChatFormatter
26
26
  from llama_index.agent.llm_compiler import LLMCompilerAgentWorker
27
27
  from llama_index.agent.lats import LATSAgentWorker
@@ -277,7 +277,19 @@ class Agent:
277
277
  llm = get_llm(LLMRole.MAIN, config=config)
278
278
  llm.callback_manager = llm_callback_manager
279
279
 
280
- if agent_type == AgentType.REACT:
280
+ if agent_type == AgentType.FUNCTION_CALLING:
281
+ prompt = _get_prompt(GENERAL_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
282
+ agent = FunctionCallingAgent.from_tools(
283
+ tools=self.tools,
284
+ llm=llm,
285
+ memory=self.memory,
286
+ verbose=self.verbose,
287
+ max_function_calls=config.max_reasoning_steps,
288
+ callback_manager=llm_callback_manager,
289
+ system_prompt = prompt,
290
+ allow_parallel_tool_calls=True,
291
+ )
292
+ elif agent_type == AgentType.REACT:
281
293
  prompt = _get_prompt(REACT_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
282
294
  agent = ReActAgent.from_tools(
283
295
  tools=self.tools,
@@ -295,7 +307,7 @@ class Agent:
295
307
  llm=llm,
296
308
  memory=self.memory,
297
309
  verbose=self.verbose,
298
- callable_manager=llm_callback_manager,
310
+ callback_manager=llm_callback_manager,
299
311
  max_function_calls=config.max_reasoning_steps,
300
312
  system_prompt=prompt,
301
313
  )
@@ -304,7 +316,7 @@ class Agent:
304
316
  tools=self.tools,
305
317
  llm=llm,
306
318
  verbose=self.verbose,
307
- callable_manager=llm_callback_manager,
319
+ callback_manager=llm_callback_manager,
308
320
  )
309
321
  agent_worker.system_prompt = _get_prompt(
310
322
  _get_llm_compiler_prompt(agent_worker.system_prompt, self._topic, self._custom_instructions),
@@ -322,7 +334,7 @@ class Agent:
322
334
  num_expansions=3,
323
335
  max_rollouts=-1,
324
336
  verbose=self.verbose,
325
- callable_manager=llm_callback_manager,
337
+ callback_manager=llm_callback_manager,
326
338
  )
327
339
  prompt = _get_prompt(REACT_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
328
340
  agent_worker.chat_formatter = ReActChatFormatter(system_header=prompt)
@@ -707,6 +719,8 @@ class Agent:
707
719
  """
708
720
  max_attempts = 4 if self.fallback_agent_config else 2
709
721
  attempt = 0
722
+ orig_llm = self.llm.metadata.model_name
723
+ last_error = None
710
724
  while attempt < max_attempts:
711
725
  try:
712
726
  current_agent = self._get_current_agent()
@@ -718,16 +732,20 @@ class Agent:
718
732
  self.query_logging_callback(prompt, agent_response.response)
719
733
  return agent_response
720
734
 
721
- except Exception:
735
+ except Exception as e:
736
+ last_error = e
722
737
  if attempt >= 2:
723
738
  if self.verbose:
724
- print(f"LLM call failed on attempt {attempt+1}. Switching agent configuration.")
739
+ print(f"LLM call failed on attempt {attempt}. Switching agent configuration.")
725
740
  self._switch_agent_config()
726
741
  time.sleep(1)
727
742
  attempt += 1
728
743
 
729
744
  return AgentResponse(
730
- response=f"LLM failure can't be resolved after {max_attempts} attempts."
745
+ response=(
746
+ f"For {orig_llm} LLM - failure can't be resolved after "
747
+ f"{max_attempts} attempts ({last_error}."
748
+ )
731
749
  )
732
750
 
733
751
  def stream_chat(self, prompt: str) -> AgentStreamingResponse: # type: ignore
@@ -750,6 +768,7 @@ class Agent:
750
768
  """
751
769
  max_attempts = 4 if self.fallback_agent_config else 2
752
770
  attempt = 0
771
+ orig_llm = self.llm.metadata.model_name
753
772
  while attempt < max_attempts:
754
773
  try:
755
774
  current_agent = self._get_current_agent()
@@ -770,16 +789,20 @@ class Agent:
770
789
  agent_response.async_response_gen = _stream_response_wrapper # Override the generator
771
790
  return agent_response
772
791
 
773
- except Exception:
792
+ except Exception as e:
793
+ last_error = e
774
794
  if attempt >= 2:
775
795
  if self.verbose:
776
- print("LLM call failed. Switching agent configuration.")
796
+ print(f"LLM call failed on attempt {attempt}. Switching agent configuration.")
777
797
  self._switch_agent_config()
778
798
  time.sleep(1)
779
799
  attempt += 1
780
800
 
781
801
  return AgentResponse(
782
- response=f"LLM failure can't be resolved after {max_attempts} attempts."
802
+ response=(
803
+ f"For {orig_llm} LLM - failure can't be resolved after "
804
+ f"{max_attempts} attempts ({last_error})."
805
+ )
783
806
  )
784
807
 
785
808
  #
@@ -843,7 +866,6 @@ class Agent:
843
866
  def to_dict(self) -> Dict[str, Any]:
844
867
  """Serialize the Agent instance to a dictionary."""
845
868
  tool_info = []
846
-
847
869
  for tool in self.tools:
848
870
  if hasattr(tool.metadata, "fn_schema"):
849
871
  fn_schema_cls = tool.metadata.fn_schema