versionhq 1.1.11.8__py3-none-any.whl → 1.1.12.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.
versionhq/__init__.py CHANGED
@@ -1,11 +1,8 @@
1
+ # silence some warnings
1
2
  import warnings
2
-
3
- warnings.filterwarnings(
4
- "ignore",
5
- message="Pydantic serializer warnings:",
6
- category=UserWarning,
7
- module="pydantic.main",
8
- )
3
+ warnings.filterwarnings(action="ignore", message="Pydantic serializer warnings:", category=UserWarning, module="pydantic.main")
4
+ warnings.filterwarnings(action="ignore", category=UserWarning, module="pydantic._internal")
5
+ warnings.filterwarnings(action="ignore", module="LiteLLM:utils")
9
6
 
10
7
  from versionhq.agent.model import Agent
11
8
  from versionhq.clients.customer.model import Customer
@@ -17,7 +14,7 @@ from versionhq.tool.model import Tool
17
14
  from versionhq.tool.composio_tool import ComposioHandler
18
15
 
19
16
 
20
- __version__ = "1.1.11.8"
17
+ __version__ = "1.1.12.1"
21
18
  __all__ = [
22
19
  "Agent",
23
20
  "Customer",
@@ -36,10 +36,15 @@ class Printer:
36
36
 
37
37
 
38
38
  class Logger(BaseModel):
39
+ """
40
+ Control CLI messages.
41
+ Color: red = error, yellow = warning, blue = info (from vhq), green = info (from third party)
42
+ """
43
+
39
44
  verbose: bool = Field(default=True)
40
45
  _printer: Printer = PrivateAttr(default_factory=Printer)
41
46
 
42
47
  def log(self, level, message, color="yellow"):
43
48
  if self.verbose:
44
49
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
45
- self._printer.print(f"\n{timestamp} - versionHQ - {level.upper()}: {message}", color=color)
50
+ self._printer.print(f"\n{timestamp} - versionHQ [{level.upper()}]: {message}", color=color)
@@ -0,0 +1,31 @@
1
+ from versionhq.agent.model import Agent
2
+ from versionhq.llm.model import DEFAULT_MODEL_NAME
3
+
4
+ """
5
+ In-house agents to be called across the project.
6
+ [Rules] agents' names and roles start with `vhq_`.
7
+ """
8
+
9
+ vhq_client_manager = Agent(
10
+ role="vhq-Client Manager",
11
+ goal="Efficiently communicate with the client on the task progress",
12
+ llm=DEFAULT_MODEL_NAME
13
+ )
14
+
15
+ vhq_task_evaluator = Agent(
16
+ role="vhq-Task Evaluator",
17
+ goal="score the output according to the given evaluation criteria.",
18
+ llm=DEFAULT_MODEL_NAME,
19
+ llm_config=dict(top_p=0.8, top_k=30, max_tokens=5000, temperature=0.9),
20
+ maxit=1,
21
+ max_retry_limit=1
22
+ )
23
+
24
+ vhq_formation_planner = Agent(
25
+ role="vhq-Formation Planner",
26
+ goal="Plan a formation of agents based on the given task descirption.",
27
+ llm="gemini/gemini-2.0-flash-exp",
28
+ llm_config=dict(top_p=0.8, top_k=30, temperature=0.9),
29
+ maxit=1,
30
+ max_retry_limit=1
31
+ )
versionhq/agent/model.py CHANGED
@@ -165,13 +165,16 @@ class Agent(BaseModel):
165
165
  Set up `llm` and `function_calling_llm` as valid LLM objects using the given values.
166
166
  """
167
167
  self.agent_ops_agent_name = self.role
168
- self.llm = self._set_llm(llm=self.llm)
168
+ self.llm = self._convert_to_llm_class(llm=self.llm)
169
+
169
170
  function_calling_llm = self.function_calling_llm if self.function_calling_llm else self.llm if self.llm else None
170
- self.function_calling_llm = self._set_llm(llm=function_calling_llm)
171
+ function_calling_llm = self._convert_to_llm_class(llm=function_calling_llm)
172
+ if function_calling_llm._supports_function_calling():
173
+ self.function_calling_llm = function_calling_llm
171
174
  return self
172
175
 
173
176
 
174
- def _set_llm(self, llm: Any | None) -> LLM:
177
+ def _convert_to_llm_class(self, llm: Any | None) -> LLM:
175
178
  llm = llm if llm is not None else DEFAULT_MODEL_NAME
176
179
 
177
180
  match llm:
@@ -413,7 +416,7 @@ class Agent(BaseModel):
413
416
  task.tokens = self.llm._tokens
414
417
 
415
418
  task_execution_counter += 1
416
- self._logger.log(level="info", message=f"Agent response: {raw_response}", color="blue")
419
+ self._logger.log(level="info", message=f"Agent response: {raw_response}", color="green")
417
420
  return raw_response
418
421
 
419
422
  except Exception as e:
@@ -429,7 +432,7 @@ class Agent(BaseModel):
429
432
  iterations += 1
430
433
 
431
434
  task_execution_counter += 1
432
- self._logger.log(level="info", message=f"Agent #{task_execution_counter} response: {raw_response}", color="blue")
435
+ self._logger.log(level="info", message=f"Agent #{task_execution_counter} response: {raw_response}", color="green")
433
436
  return raw_response
434
437
 
435
438
  if not raw_response:
@@ -474,6 +477,7 @@ class Agent(BaseModel):
474
477
  task_prompt += memory.strip()
475
478
 
476
479
 
480
+ ## comment out for now
477
481
  # if self.team and self.team._train:
478
482
  # task_prompt = self._training_handler(task_prompt=task_prompt)
479
483
  # else:
versionhq/llm/llm_vars.py CHANGED
@@ -6,29 +6,20 @@ JSON_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_
6
6
  PROVIDERS = [
7
7
  "openai",
8
8
  "gemini",
9
- "sagemaker",
10
- "huggingface", # need api base
9
+ "openrouter",
10
+ "huggingface",
11
11
  "anthropic",
12
+ "sagemaker",
13
+ "bedrock",
12
14
  "ollama",
13
15
  "watson",
14
- "bedrock",
15
16
  "azure",
16
17
  "cerebras",
17
18
  "llama",
18
19
  ]
19
20
 
20
21
  ENDPOINT_PROVIDERS = [
21
- # "openai",
22
- # "gemini",
23
- # "sagemaker",
24
22
  "huggingface",
25
- # "anthropic",
26
- # "ollama",
27
- # "watson",
28
- # "bedrock",
29
- # "azure",
30
- # "cerebras",
31
- # "llama",
32
23
  ]
33
24
 
34
25
  """
@@ -57,10 +48,14 @@ MODELS = {
57
48
  "anthropic": [
58
49
  "claude-3-5-sonnet-20241022",
59
50
  "claude-3-5-sonnet-20240620",
60
- "claude-3-sonnet-20240229",
51
+ "claude-3-haiku-2024030",
61
52
  "claude-3-opus-20240229",
62
53
  "claude-3-haiku-20240307",
63
54
  ],
55
+ "openrouter": [
56
+ "openrouter/deepseek/deepseek-r1:free",
57
+ "openrouter/qwen/qwen-2.5-72b-instruct",
58
+ ],
64
59
  "huggingface": [
65
60
  "huggingface/qwen/qwen2.5-VL-72B-Instruct",
66
61
  ],
@@ -78,11 +73,6 @@ MODELS = {
78
73
  "ollama/mixtral",
79
74
  "ollama/mixtral-8x22B-Instruct-v0.1",
80
75
  ],
81
- "deepseek": [
82
- "deepseek/deepseek-reasoner",
83
-
84
- ],
85
-
86
76
  # "watson": [
87
77
  # "watsonx/meta-llama/llama-3-1-70b-instruct",
88
78
  # "watsonx/meta-llama/llama-3-1-8b-instruct",
@@ -98,7 +88,6 @@ MODELS = {
98
88
  "bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
99
89
  "bedrock/anthropic.claude-3-haiku-20240307-v1:0",
100
90
  "bedrock/anthropic.claude-3-opus-20240229-v1:0",
101
- # "bedrock/anthropic.claude-v2:1",
102
91
  "bedrock/anthropic.claude-v2",
103
92
  "bedrock/anthropic.claude-instant-v1",
104
93
  "bedrock/meta.llama3-1-405b-instruct-v1:0",
@@ -124,24 +113,17 @@ MODELS = {
124
113
  KEYS = {
125
114
  "openai": ["OPENAI_API_KEY"],
126
115
  "gemini": ["GEMINI_API_KEY"],
127
- "sagemaker": ["AWS_ACCESS_KEY_ID", "ADW_SECURET_ACCESS_KEY", "AWS_REGION_NAME"],
128
116
  "anthropic": ["ANTHROPIC_API_KEY"],
117
+ "huggingface": ["HUGGINGFACE_API_KEY", ],
118
+ "sagemaker": ["AWS_ACCESS_KEY_ID", "ADW_SECURET_ACCESS_KEY", "AWS_REGION_NAME"],
129
119
  }
130
120
 
131
121
 
132
- """
133
- Use base_url to specify
134
- """
135
- BASE_URLS = {
136
- "deepseek": "https://api.deepseek.com"
137
- }
138
-
139
122
 
140
123
  """
141
124
  Max input token size by the model.
142
125
  """
143
126
  LLM_CONTEXT_WINDOW_SIZES = {
144
- "gpt-3.5-turbo": 8192,
145
127
  "gpt-4": 8192,
146
128
  "gpt-4o": 128000,
147
129
  "gpt-4o-mini": 128000,
@@ -160,6 +142,7 @@ LLM_CONTEXT_WINDOW_SIZES = {
160
142
  "claude-3-sonnet-20240229": 200000,
161
143
  "claude-3-opus-20240229": 200000,
162
144
  "claude-3-haiku-20240307": 200000,
145
+ "claude-3-5-sonnet-2024102": 200000,
163
146
 
164
147
  "deepseek-chat": 128000,
165
148
  "deepseek/deepseek-reasoner": 8192,
@@ -177,111 +160,18 @@ LLM_CONTEXT_WINDOW_SIZES = {
177
160
  "llama3-70b-8192": 8192,
178
161
  "llama3-8b-8192": 8192,
179
162
  "mixtral-8x7b-32768": 32768,
180
- "claude-3-5-sonnet-2024102": 200000,
181
- }
182
-
183
-
184
-
185
-
186
- LLM_BASE_URL_KEY_NAMES = {
187
- "openai": "OPENAI_API_BASE",
188
- "gemini": "GEMINI_API_BASE",
189
- "anthropic": "ANTHROPIC_API_BASE",
190
- }
191
-
192
- LLM_VARS = {
193
- "openai": [
194
- {
195
- "prompt": "Enter your OPENAI API key (press Enter to skip)",
196
- "key_name": "OPENAI_API_KEY",
197
- }
198
- ],
199
- "anthropic": [
200
- {
201
- "prompt": "Enter your ANTHROPIC API key (press Enter to skip)",
202
- "key_name": "ANTHROPIC_API_KEY",
203
- }
204
- ],
205
- "gemini": [
206
- {
207
- "prompt": "Enter your GEMINI API key (press Enter to skip)",
208
- "key_name": "GEMINI_API_KEY",
209
- }
210
- ],
211
- "watson": [
212
- {
213
- "prompt": "Enter your WATSONX URL (press Enter to skip)",
214
- "key_name": "WATSONX_URL",
215
- },
216
- {
217
- "prompt": "Enter your WATSONX API Key (press Enter to skip)",
218
- "key_name": "WATSONX_APIKEY",
219
- },
220
- {
221
- "prompt": "Enter your WATSONX Project Id (press Enter to skip)",
222
- "key_name": "WATSONX_PROJECT_ID",
223
- },
224
- ],
225
- "ollama": [
226
- {
227
- "default": True,
228
- "API_BASE": "http://localhost:11434",
229
- }
230
- ],
231
- "bedrock": [
232
- {
233
- "prompt": "Enter your AWS Access Key ID (press Enter to skip)",
234
- "key_name": "AWS_ACCESS_KEY_ID",
235
- },
236
- {
237
- "prompt": "Enter your AWS Secret Access Key (press Enter to skip)",
238
- "key_name": "AWS_SECRET_ACCESS_KEY",
239
- },
240
- {
241
- "prompt": "Enter your AWS Region Name (press Enter to skip)",
242
- "key_name": "AWS_REGION_NAME",
243
- },
244
- ],
245
- "azure": [
246
- {
247
- "prompt": "Enter your Azure deployment name (must start with 'azure/')",
248
- "key_name": "model",
249
- },
250
- {
251
- "prompt": "Enter your AZURE API key (press Enter to skip)",
252
- "key_name": "AZURE_API_KEY",
253
- },
254
- {
255
- "prompt": "Enter your AZURE API base URL (press Enter to skip)",
256
- "key_name": "AZURE_API_BASE",
257
- },
258
- {
259
- "prompt": "Enter your AZURE API version (press Enter to skip)",
260
- "key_name": "AZURE_API_VERSION",
261
- },
262
- ],
263
- "cerebras": [
264
- {
265
- "prompt": "Enter your Cerebras model name (must start with 'cerebras/')",
266
- "key_name": "model",
267
- },
268
- {
269
- "prompt": "Enter your Cerebras API version (press Enter to skip)",
270
- "key_name": "CEREBRAS_API_KEY",
271
- },
272
- ],
273
163
  }
274
164
 
275
165
 
276
166
 
277
167
  """
278
- Params for litellm.completion() func. Address common/unique params to each provider.
168
+ Params for litellm.completion().
279
169
  """
280
170
 
281
171
  PARAMS = {
282
172
  "litellm": [
283
173
  "api_base",
284
- "api_version,"
174
+ "api_version,",
285
175
  "num_retries",
286
176
  "context_window_fallback_dict",
287
177
  "fallbacks",
versionhq/llm/model.py CHANGED
@@ -1,4 +1,3 @@
1
- import logging
2
1
  import json
3
2
  import os
4
3
  import sys
@@ -6,12 +5,11 @@ import threading
6
5
  import warnings
7
6
  from dotenv import load_dotenv
8
7
  import litellm
9
- from litellm import get_supported_openai_params, JSONSchemaValidationError
8
+ from litellm import JSONSchemaValidationError
10
9
  from contextlib import contextmanager
11
10
  from typing import Any, Dict, List, Optional
12
11
  from typing_extensions import Self
13
- from pydantic import BaseModel, Field, PrivateAttr, field_validator, model_validator, create_model, InstanceOf, ConfigDict
14
- from pydantic_core import PydanticCustomError
12
+ from pydantic import BaseModel, Field, PrivateAttr, model_validator, ConfigDict
15
13
 
16
14
  from versionhq.llm.llm_vars import LLM_CONTEXT_WINDOW_SIZES, MODELS, PARAMS, PROVIDERS, ENDPOINT_PROVIDERS
17
15
  from versionhq.tool.model import Tool, ToolSet
@@ -25,10 +23,6 @@ DEFAULT_CONTEXT_WINDOW_SIZE = int(8192 * 0.75)
25
23
  DEFAULT_MODEL_NAME = os.environ.get("DEFAULT_MODEL_NAME", "gpt-4o-mini")
26
24
  DEFAULT_MODEL_PROVIDER_NAME = os.environ.get("DEFAULT_MODEL_PROVIDER_NAME", "openai")
27
25
 
28
- # proxy_openai_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), organization="versionhq", base_url=LITELLM_API_BASE)
29
- # openai_client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
30
-
31
-
32
26
  class FilteredStream:
33
27
  def __init__(self, original_stream):
34
28
  self._original_stream = original_stream
@@ -53,7 +47,8 @@ class FilteredStream:
53
47
  @contextmanager
54
48
  def suppress_warnings():
55
49
  with warnings.catch_warnings():
56
- warnings.filterwarnings("ignore")
50
+ litellm.set_verbose = False
51
+ warnings.filterwarnings(action="ignore")
57
52
  old_stdout = sys.stdout
58
53
  old_stderr = sys.stderr
59
54
  sys.stdout = FilteredStream(old_stdout)
@@ -83,11 +78,11 @@ class LLM(BaseModel):
83
78
  api_key: Optional[str] = Field(default=None, description="api key to access the model")
84
79
 
85
80
  # optional params
81
+ response_format: Optional[Any] = Field(default=None)
86
82
  timeout: Optional[float | int] = Field(default=None)
87
83
  max_tokens: Optional[int] = Field(default=None)
88
84
  max_completion_tokens: Optional[int] = Field(default=None)
89
85
  context_window_size: Optional[int] = Field(default=DEFAULT_CONTEXT_WINDOW_SIZE)
90
- callbacks: List[Any] = Field(default_factory=list)
91
86
  temperature: Optional[float] = Field(default=None)
92
87
  top_p: Optional[float] = Field(default=None)
93
88
  n: Optional[int] = Field(default=None)
@@ -98,8 +93,8 @@ class LLM(BaseModel):
98
93
  seed: Optional[int] = Field(default=None)
99
94
  logprobs: Optional[bool] = Field(default=None)
100
95
  top_logprobs: Optional[int] = Field(default=None)
101
- response_format: Optional[Any] = Field(default=None)
102
96
  tools: Optional[List[Dict[str, Any]]] = Field(default_factory=list, description="store a list of tool properties")
97
+ callbacks: List[Any] = Field(default_factory=list)
103
98
 
104
99
  # LiteLLM specific fields
105
100
  api_base: Optional[str] = Field(default=None, description="litellm specific field - api base of the model provider")
@@ -193,7 +188,7 @@ class LLM(BaseModel):
193
188
  @model_validator(mode="after")
194
189
  def validate_model_params(self) -> Self:
195
190
  """
196
- After setting up a valid model, provider, interface provider, add params to the model.
191
+ Set up valid params to the model after setting up a valid model, provider, interface provider names.
197
192
  """
198
193
  self._tokens = 0
199
194
 
@@ -216,19 +211,28 @@ class LLM(BaseModel):
216
211
  return self
217
212
 
218
213
 
219
- def _create_valid_params(self, config: Dict[str, Any], provider: str = None) -> Dict[str, Any]:
220
- params = dict()
221
- valid_keys = list()
222
- provider = provider if provider else self.provider if self.provider else None
223
- valid_keys = PARAMS.get("litellm") + PARAMS.get("common") + PARAMS.get(provider) if provider and PARAMS.get(provider) else PARAMS.get("litellm") + PARAMS.get("common")
214
+ def _create_valid_params(self, config: Dict[str, Any]) -> Dict[str, Any]:
215
+ """
216
+ Return valid params (model + litellm original params) from the given config dict.
217
+ """
218
+
219
+ valid_params, valid_keys = dict(), list()
220
+
221
+ if self.model:
222
+ valid_keys = litellm.get_supported_openai_params(model=self.model, custom_llm_provider=self.endpoint_provider, request_type="chat_completion")
223
+
224
+ if not valid_keys:
225
+ valid_keys = PARAMS.get("common")
226
+
227
+ valid_keys += PARAMS.get("litellm")
224
228
 
225
229
  for item in valid_keys:
226
230
  if hasattr(self, item) and getattr(self, item):
227
- params[item] = getattr(self, item)
228
- elif item in config:
229
- params[item] = config[item]
231
+ valid_params[item] = getattr(self, item)
232
+ elif item in config and config[item]:
233
+ valid_params[item] = config[item]
230
234
 
231
- return params
235
+ return valid_params
232
236
 
233
237
 
234
238
  def call(
@@ -250,21 +254,18 @@ class LLM(BaseModel):
250
254
  self._set_callbacks(self.callbacks) # passed by agent
251
255
 
252
256
  try:
253
- provider = self.provider if self.provider else DEFAULT_MODEL_PROVIDER_NAME
254
257
  self.response_format = { "type": "json_object" } if tool_res_as_final == True else response_format
255
258
 
256
259
  if not tools:
257
260
  params = self._create_valid_params(config=config)
258
- res = litellm.completion(messages=messages, stream=False, **params)
261
+ res = litellm.completion(model=self.model, messages=messages, stream=False, **params)
259
262
  self._tokens += int(res["usage"]["total_tokens"])
260
263
  return res["choices"][0]["message"]["content"]
261
264
 
262
265
  else:
263
266
  self.tools = [item.tool.properties if isinstance(item, ToolSet) else item.properties for item in tools]
264
-
265
- # if provider == "openai":
266
- params = self._create_valid_params(config=config, provider=provider)
267
- res = litellm.completion(messages=messages, model=self.model, tools=self.tools)
267
+ params = self._create_valid_params(config=config)
268
+ res = litellm.completion(model=self.model, messages=messages, **params)
268
269
  tool_calls = res.choices[0].message.tool_calls
269
270
  tool_res = ""
270
271
 
@@ -304,7 +305,7 @@ class LLM(BaseModel):
304
305
  if tool_res_as_final:
305
306
  return tool_res
306
307
  else:
307
- res = litellm.completione(messages=messages, model=self.model, tools=self.tools)
308
+ res = litellm.completion(model=self.model, messages=messages, **params)
308
309
  self._tokens += int(res["usage"]["total_tokens"])
309
310
  return res.choices[0].message.content
310
311
 
@@ -320,20 +321,17 @@ class LLM(BaseModel):
320
321
 
321
322
  def _supports_function_calling(self) -> bool:
322
323
  try:
323
- params = get_supported_openai_params(model=self.model)
324
- return "response_format" in params
324
+ if self.model:
325
+ params = litellm.get_supported_openai_params(model=self.model)
326
+ return "response_format" in params if params else False
325
327
  except Exception as e:
326
- self._logger.log(level="error", message=f"Failed to get supported params: {str(e)}", color="red")
328
+ self._logger.log(level="warning", message=f"Failed to get supported params: {str(e)}", color="yellow")
327
329
  return False
328
330
 
329
331
 
330
332
  def _supports_stop_words(self) -> bool:
331
- try:
332
- params = get_supported_openai_params(model=self.model)
333
- return "stop" in params
334
- except Exception as e:
335
- self._logger.log(level="error", message=f"Failed to get supported params: {str(e)}", color="red")
336
- return False
333
+ supported_params = litellm.get_supported_openai_params(model=self.model, custom_llm_provider=self.endpoint_provider)
334
+ return "stop" in supported_params if supported_params else False
337
335
 
338
336
 
339
337
  def _get_context_window_size(self) -> int:
@@ -1,15 +1,13 @@
1
1
  from typing import List, Optional, Dict, Any
2
2
  from typing_extensions import Self
3
3
 
4
- from pydantic import BaseModel, Field, InstanceOf, model_validator
4
+ from pydantic import BaseModel, Field, model_validator
5
5
 
6
6
  """
7
7
  Evaluate task output from accuracy, token consumption, latency perspectives, and mark the score from 0 to 1.
8
8
  """
9
9
 
10
10
 
11
-
12
-
13
11
  class ScoreFormat:
14
12
  def __init__(self, rate: float | int = 0, weight: int = 1):
15
13
  self.rate = rate
@@ -72,16 +70,16 @@ class EvaluationItem(BaseModel):
72
70
 
73
71
 
74
72
  class Evaluation(BaseModel):
75
- # expected_outcome: Optional[str] = Field(default=None, description="human input on expected outcome")
76
73
  items: List[EvaluationItem] = []
77
74
  latency: int = Field(default=None, description="seconds")
78
75
  tokens: int = Field(default=None, description="tokens consumed")
79
76
  responsible_agent: Any = Field(default=None, description="store agent instance that evaluates the outcome")
80
77
 
78
+
81
79
  @model_validator(mode="after")
82
80
  def set_up_responsible_agent(self) -> Self:
83
- from versionhq.agent.default_agents import task_evaluator
84
- self.responsible_agent = task_evaluator
81
+ from versionhq.agent.inhouse_agents import vhq_task_evaluator
82
+ self.responsible_agent = vhq_task_evaluator
85
83
  return self
86
84
 
87
85
 
versionhq/task/model.py CHANGED
@@ -8,7 +8,7 @@ from hashlib import md5
8
8
  from typing import Any, Dict, List, Set, Optional, Tuple, Callable, Type, TypeVar
9
9
  from typing_extensions import Annotated, Self
10
10
 
11
- from pydantic import UUID4, BaseModel, Field, PrivateAttr, field_validator, model_validator, create_model, InstanceOf, field_validator
11
+ from pydantic import UUID4, BaseModel, Field, PrivateAttr, field_validator, model_validator, InstanceOf, field_validator
12
12
  from pydantic_core import PydanticCustomError
13
13
 
14
14
  from versionhq._utils.process_config import process_config
@@ -286,7 +286,7 @@ class Task(BaseModel):
286
286
  processed_by_agents: Set[str] = Field(default_factory=set, description="store responsible agents' roles")
287
287
  tools_errors: int = 0
288
288
  delegations: int = 0
289
- latency: int | float = 0 # execution latency in sec
289
+ latency: int | float = 0 # job latency in sec
290
290
  tokens: int = 0 # tokens consumed
291
291
 
292
292
 
@@ -412,37 +412,38 @@ Ref. Output image: {output_formats_to_follow}
412
412
 
413
413
  response_format: Dict[str, Any] = None
414
414
 
415
- # match model_provider:
416
- # case "openai":
417
- if self.response_fields:
418
- properties, required_fields = {}, []
419
- for i, item in enumerate(self.response_fields):
420
- if item:
421
- if item.data_type is dict:
422
- properties.update(item._format_props())
423
- else:
424
- properties.update(item._format_props())
425
-
426
- required_fields.append(item.title)
427
-
428
- response_schema = {
429
- "type": "object",
430
- "properties": properties,
431
- "required": required_fields,
432
- "additionalProperties": False,
433
- }
415
+ if model_provider == "openrouter":
416
+ return response_format
434
417
 
435
- response_format = {
436
- "type": "json_schema",
437
- "json_schema": { "name": "outcome", "schema": response_schema }
438
- }
418
+ else:
419
+ if self.response_fields:
420
+ properties, required_fields = {}, []
421
+ for i, item in enumerate(self.response_fields):
422
+ if item:
423
+ if item.data_type is dict:
424
+ properties.update(item._format_props())
425
+ else:
426
+ properties.update(item._format_props())
427
+
428
+ required_fields.append(item.title)
429
+
430
+ response_schema = {
431
+ "type": "object",
432
+ "properties": properties,
433
+ "required": required_fields,
434
+ "additionalProperties": False,
435
+ }
436
+
437
+ response_format = {
438
+ "type": "json_schema",
439
+ "json_schema": { "name": "outcome", "schema": response_schema }
440
+ }
439
441
 
440
442
 
441
- elif self.pydantic_output:
442
- response_format = StructuredOutput(response_format=self.pydantic_output)._format()
443
+ elif self.pydantic_output:
444
+ response_format = StructuredOutput(response_format=self.pydantic_output)._format()
443
445
 
444
- # case "gemini":
445
- return response_format
446
+ return response_format
446
447
 
447
448
 
448
449
  def _create_json_output(self, raw: str) -> Dict[str, Any]:
@@ -612,7 +613,7 @@ Ref. Output image: {output_formats_to_follow}
612
613
  task_output: InstanceOf[TaskOutput] = None
613
614
  tool_output: str | list = None
614
615
  task_tools: List[List[InstanceOf[Tool]| InstanceOf[ToolSet] | Type[Tool]]] = []
615
- started_at = datetime.datetime.now()
616
+ started_at, ended_at = datetime.datetime.now(), datetime.datetime.now()
616
617
 
617
618
  if self.tools:
618
619
  for item in self.tools:
@@ -638,11 +639,16 @@ Ref. Output image: {output_formats_to_follow}
638
639
 
639
640
 
640
641
  if self.tool_res_as_final == True:
642
+ started_at = datetime.datetime.now()
641
643
  tool_output = agent.execute_task(task=self, context=context, task_tools=task_tools)
644
+ ended_at = datetime.datetime.now()
642
645
  task_output = TaskOutput(task_id=self.id, tool_output=tool_output, raw=str(tool_output) if tool_output else "")
643
646
 
644
647
  else:
648
+ started_at = datetime.datetime.now()
645
649
  raw_output = agent.execute_task(task=self, context=context, task_tools=task_tools)
650
+ ended_at = datetime.datetime.now()
651
+
646
652
  json_dict_output = self._create_json_output(raw=raw_output)
647
653
  if "outcome" in json_dict_output:
648
654
  json_dict_output = self._create_json_output(raw=str(json_dict_output["outcome"]))
@@ -656,9 +662,8 @@ Ref. Output image: {output_formats_to_follow}
656
662
  json_dict=json_dict_output
657
663
  )
658
664
 
659
- ended_at = datetime.datetime.now()
660
- self.latency = (ended_at - started_at).total_seconds()
661
665
 
666
+ self.latency = (ended_at - started_at).total_seconds()
662
667
  self.output = task_output
663
668
  self.processed_by_agents.add(agent.role)
664
669
 
versionhq/team/model.py CHANGED
@@ -20,7 +20,6 @@ from versionhq._utils.usage_metrics import UsageMetrics
20
20
 
21
21
  initial_match_type = GenerateSchema.match_type
22
22
 
23
-
24
23
  def match_type(self, obj):
25
24
  if getattr(obj, "__name__", None) == "datetime":
26
25
  return core_schema.datetime_schema()
@@ -28,7 +27,6 @@ def match_type(self, obj):
28
27
 
29
28
 
30
29
  GenerateSchema.match_type = match_type
31
-
32
30
  warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")
33
31
  load_dotenv(override=True)
34
32
 
@@ -108,9 +106,14 @@ class TeamOutput(BaseModel):
108
106
 
109
107
 
110
108
  class TeamMember(BaseModel):
111
- agent: Agent | None = Field(default=None, description="store the agent to be a member")
109
+ """
110
+ A class to store a team member
111
+ """
112
+ agent: Agent | None = Field(default=None)
112
113
  is_manager: bool = Field(default=False)
113
- task: Optional[Task] = Field(default=None)
114
+ can_share_knowledge: bool = Field(default=True, description="whether to share the agent's knowledge in the team")
115
+ can_share_memory: bool = Field(default=True, description="whether to share the agent's memory in the team")
116
+ task: Optional[Task] = Field(default=None, description="task assigned to the agent")
114
117
 
115
118
  @property
116
119
  def is_idling(self):
@@ -125,17 +128,18 @@ class Team(BaseModel):
125
128
 
126
129
  __hash__ = object.__hash__
127
130
  _execution_span: Any = PrivateAttr()
128
- _logger: Logger = PrivateAttr()
131
+ _logger: Logger = PrivateAttr(default_factory=lambda: Logger(verbose=True))
129
132
  _inputs: Optional[Dict[str, Any]] = PrivateAttr(default=None)
130
133
 
131
134
  id: UUID4 = Field(default_factory=uuid.uuid4, frozen=True)
132
135
  name: Optional[str] = Field(default=None)
133
- members: List[TeamMember] = Field(default_factory=list, description="store agents' uuids and bool if it is manager")
136
+ members: List[TeamMember] = Field(default_factory=list)
137
+
138
+ # formation planning
139
+ planning_llm: Optional[Any] = Field(default=None, description="llm to generate formation")
140
+ team_tasks: Optional[List[Task]] = Field(default_factory=list, description="optional tasks for the team. can be assigned to team members later")
134
141
 
135
- # work as a team
136
- team_tasks: Optional[List[Task]] = Field(default_factory=list, description="optional tasks for the team")
137
- planning_llm: Optional[Any] = Field(default=None, description="llm to handle the planning of the team tasks (if any)")
138
- function_calling_llm: Optional[Any] = Field(default=None, description="llm to execute func after all agent execution (if any)")
142
+ # task execution rules
139
143
  prompt_file: str = Field(default="", description="path to the prompt json file to be used by the team.")
140
144
  process: TaskHandlingProcess = Field(default=TaskHandlingProcess.sequential)
141
145
 
@@ -150,7 +154,6 @@ class Team(BaseModel):
150
154
  )
151
155
  step_callback: Optional[Any] = Field(default=None, description="callback to be executed after each step for all agents execution")
152
156
 
153
- verbose: bool = Field(default=True)
154
157
  cache: bool = Field(default=True)
155
158
  memory: bool = Field(default=False, description="whether the team should use memory to store memories of its execution")
156
159
  execution_logs: List[Dict[str, Any]] = Field(default=[], description="list of execution logs for tasks")
@@ -236,7 +239,7 @@ class Team(BaseModel):
236
239
  return self
237
240
 
238
241
 
239
- def _get_responsible_agent(self, task: Task) -> Agent:
242
+ def _get_responsible_agent(self, task: Task) -> Agent | None:
240
243
  if task is None:
241
244
  return None
242
245
  else:
@@ -244,7 +247,7 @@ class Team(BaseModel):
244
247
  return None if len(res) == 0 else res[0]
245
248
 
246
249
 
247
- def _handle_team_planning(self) -> None:
250
+ def _handle_agent_formation(self) -> None:
248
251
  """
249
252
  Form a team considering agents and tasks given, and update `self.members` field:
250
253
  1. Idling managers to take the team tasks.
@@ -373,7 +376,7 @@ class Team(BaseModel):
373
376
 
374
377
  responsible_agent = self._get_responsible_agent(task)
375
378
  if responsible_agent is None:
376
- self._handle_team_planning()
379
+ self._handle_agent_formation()
377
380
 
378
381
  if isinstance(task, ConditionalTask):
379
382
  skipped_task_output = task._handle_conditional_task(task_outputs, futures, task_index, was_replayed)
@@ -415,7 +418,7 @@ class Team(BaseModel):
415
418
  metrics: List[UsageMetrics] = []
416
419
 
417
420
  if self.team_tasks or self.member_tasks_without_agent:
418
- self._handle_team_planning()
421
+ self._handle_agent_formation()
419
422
 
420
423
  if kwargs_before is not None:
421
424
  for before_callback in self.before_kickoff_callbacks:
@@ -432,9 +435,6 @@ class Team(BaseModel):
432
435
  agent = member.agent
433
436
  agent.team = self
434
437
 
435
- if not agent.function_calling_llm and self.function_calling_llm:
436
- agent.function_calling_llm = self.function_calling_llm
437
-
438
438
  if self.step_callback:
439
439
  agent.callbacks.append(self.step_callback)
440
440
 
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Version IO Sdn. Bhd.
3
+ Copyright (c) 2024-2025 Version IO Sdn. Bhd.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: versionhq
3
- Version: 1.1.11.8
3
+ Version: 1.1.12.1
4
4
  Summary: LLM orchestration frameworks for model-agnostic AI agents that handle complex outbound workflows
5
5
  Author-email: Kuriko Iwai <kuriko@versi0n.io>
6
6
  License: MIT License
7
7
 
8
- Copyright (c) 2024 Version IO Sdn. Bhd.
8
+ Copyright (c) 2024-2025 Version IO Sdn. Bhd.
9
9
 
10
10
  Permission is hereby granted, free of charge, to any person obtaining a copy
11
11
  of this software and associated documentation files (the "Software"), to deal
@@ -78,12 +78,12 @@ Requires-Dist: numpy>=1.26.4; extra == "numpy"
78
78
 
79
79
  ![MIT license](https://img.shields.io/badge/License-MIT-green)
80
80
  [![Publisher](https://github.com/versionHQ/multi-agent-system/actions/workflows/publish.yml/badge.svg)](https://github.com/versionHQ/multi-agent-system/actions/workflows/publish.yml)
81
- ![PyPI](https://img.shields.io/badge/PyPI->=v1.1.11.4-blue)
82
- ![python ver](https://img.shields.io/badge/Python->=3.12-purple)
81
+ ![PyPI](https://img.shields.io/badge/PyPI-v1.1.12+-blue)
82
+ ![python ver](https://img.shields.io/badge/Python-3.11+-purple)
83
83
  ![pyenv ver](https://img.shields.io/badge/pyenv-2.5.0-orange)
84
84
 
85
85
 
86
- LLM orchestration frameworks to deploy multi-agent systems with task-based formation.
86
+ LLM orchestration frameworks to deploy multi-agent systems and automate complex tasks with network formations.
87
87
 
88
88
  **Visit:**
89
89
 
@@ -122,15 +122,16 @@ LLM orchestration frameworks to deploy multi-agent systems with task-based forma
122
122
 
123
123
  ## Key Features
124
124
 
125
- Generate mulit-agent systems depending on the complexity of the task, and execute the task with agents of choice.
125
+ Generate multi-agent systems based on the task complexity, execute tasks, and evaluate output based on the given criteria.
126
126
 
127
- Model-agnostic agents can handle RAG tools, tools, callbacks, and knowledge sharing among other agents.
127
+ Agents are model-agnostic, and can handle and share RAG tools, knowledge, memory, and callbacks among other agents. (self-learn)
128
128
 
129
129
 
130
130
  ### Agent formation
131
- Depending on the task complexity, agents can make a different formation.
132
131
 
133
- You can specify which formation you want them to generate, or let the agent decide if you don’t have a clear plan.
132
+ Agents adapt their formation based on task complexity.
133
+
134
+ You can specify a desired formation or allow the agents to determine it autonomously (default).
134
135
 
135
136
 
136
137
  | | **Solo Agent** | **Supervising** | **Network** | **Random** |
@@ -1,13 +1,13 @@
1
- versionhq/__init__.py,sha256=9QPw8-DjsW5Z2vOHQUBb-AMSyIR2RFcFkR42aXVbUFc,863
1
+ versionhq/__init__.py,sha256=oJDsufVGH28Hszr45GDKyjfs_OKDZaNrAhMOS4f9RmY,1031
2
2
  versionhq/_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  versionhq/_utils/i18n.py,sha256=TwA_PnYfDLA6VqlUDPuybdV9lgi3Frh_ASsb_X8jJo8,1483
4
- versionhq/_utils/logger.py,sha256=U-MpeGueA6YS8Ptfy0VnU_ePsZP-8Pvkvi0tZ4s_UMg,1438
4
+ versionhq/_utils/logger.py,sha256=j9SlQPIefdVUlwpGfJY83E2BUt1ejWgZ2M2I8aMyQ3c,1579
5
5
  versionhq/_utils/process_config.py,sha256=jbPGXK2Kb4iyCugJ3FwRJuU0wL5Trq2x4xFQz2uOyFY,746
6
6
  versionhq/_utils/usage_metrics.py,sha256=hhq1OCW8Z4V93vwW2O2j528EyjOlF8wlTsX5IL-7asA,1106
7
7
  versionhq/_utils/vars.py,sha256=bZ5Dx_bFKlt3hi4-NNGXqdk7B23If_WaTIju2fiTyPQ,57
8
8
  versionhq/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- versionhq/agent/default_agents.py,sha256=Sea3xDswxxMccer1vVDhp1E5etXW3ddf2n20JTMHgqs,503
10
- versionhq/agent/model.py,sha256=U6kz8EE4tJYk9HBg4qeB2_-297ROEORxP_gE6C89aH0,22232
9
+ versionhq/agent/inhouse_agents.py,sha256=DLwSREmFICF0Wv9IvEXp0gu1yOXJYOex0980Vi0NRWw,913
10
+ versionhq/agent/model.py,sha256=1Y5au6ue6B4UbtoBL00kVATbl_0_IzY_-SBkuzVvL94,22423
11
11
  versionhq/agent/parser.py,sha256=riG0dkdQCxH7uJ0AbdVdg7WvL0BXhUgJht0VtQvxJBc,4082
12
12
  versionhq/agent/rpm_controller.py,sha256=7AKIEPbWBq_ESOZCaiKVOGjfSPHd2qwg6-wbBlhqC0g,2367
13
13
  versionhq/agent/TEMPLATES/Backstory.py,sha256=IAhGnnt6VUMe3wO6IzeyZPDNu7XE7Uiu3VEXUreOcKs,532
@@ -28,8 +28,8 @@ versionhq/knowledge/source.py,sha256=WOARChmm_cNtBD-xGo4RoYmcuodzdalctXI-gDBCW6k
28
28
  versionhq/knowledge/source_docling.py,sha256=hhHn3rS4KVsFKEPWcfllM8VxSL86PckZdAHDZNQNOq8,5411
29
29
  versionhq/knowledge/storage.py,sha256=7oxCg3W9mFjYH1YmuH9kFtTbNxquzYFjuUjd_TlsB9E,8170
30
30
  versionhq/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
- versionhq/llm/llm_vars.py,sha256=48IvN6w6h6QJUWqO0A44begGLoUbBaaS-HPO_wp7c84,9588
32
- versionhq/llm/model.py,sha256=0qe3oC5u42erVBHc76WRpDKH9PDTzXyaraIuDJ6bDAY,15426
31
+ versionhq/llm/llm_vars.py,sha256=asJtkKCcD0WWIbyVn7CYOWg-WZ6MSKS9lIRaYIkdib4,6778
32
+ versionhq/llm/model.py,sha256=wSjRGyk9AZtvDqNfcyyeOMoV_hpTaUHCM849hBF0MhU,15145
33
33
  versionhq/memory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  versionhq/memory/contextual_memory.py,sha256=tCsOOAUnfrOL7YiakqGoi3uShzzS870TmGnlGd3z_A4,3556
35
35
  versionhq/memory/model.py,sha256=6Sy-cnrhHNIx3ZN38uNO7d8YywIl_uo_OvDVzVM-w14,5755
@@ -41,14 +41,14 @@ versionhq/storage/rag_storage.py,sha256=fBk-RJuFRPOH4gI9E67tkhJnTBoChWocSP2PdWUY
41
41
  versionhq/storage/task_output_storage.py,sha256=gCsZywZ2SaNA1pYIsJk6BTrcpGp79TZTviZkWQF5USs,4579
42
42
  versionhq/storage/utils.py,sha256=ByYXPoEIGJYLUqz-DWjbCAnneNrH1otiYbp12SCILpM,747
43
43
  versionhq/task/__init__.py,sha256=l2r_g01i91JAGlOoHZP_Gh2WCk6mo9D19lcqt7sKMpQ,186
44
- versionhq/task/evaluate.py,sha256=RCaFa9N4IibAYLWKUlTn6lWiQoI7t4f_XZVUvecjTxs,3486
44
+ versionhq/task/evaluate.py,sha256=sG_PFotpuRbDLW0rGDULseBk1uP8I0vYYtkh1npO0KE,3374
45
45
  versionhq/task/formatter.py,sha256=N8Kmk9vtrMtBdgJ8J7RmlKNMdZWSmV8O1bDexmCWgU0,643
46
46
  versionhq/task/log_handler.py,sha256=KJRrcNZgFSKhlNzvtYFnvtp6xukaF1s7ifX9u4zWrN8,1683
47
- versionhq/task/model.py,sha256=DCm2jS0RFm4iPkepzKbNgODUdxOtGCV0RCINMaI0c_Q,30162
47
+ versionhq/task/model.py,sha256=kR4oqoT44xVbbTGK-gtVdfMz3m-riV62XumzRyqomiU,30418
48
48
  versionhq/task/structured_response.py,sha256=YxuWcDMHcZLzdxI1ihW99Y-i6nl8yXBQ5Q_dFQac8jw,4837
49
49
  versionhq/task/TEMPLATES/Description.py,sha256=bChflSWGGQo9JpnO6QX6Ng9pnONiTf-zwQ3ke4xQgSQ,357
50
50
  versionhq/team/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
- versionhq/team/model.py,sha256=NzcRXWwP0adWL9vsnsmI-A5dOcE3199FGmGgemUB2VA,20043
51
+ versionhq/team/model.py,sha256=MgjqigmEDLnmDzYfVnbGnwp7MeXmZ-zsgyWR2Vb2FAU,20036
52
52
  versionhq/team/team_planner.py,sha256=UyIpw7GoRQXlgLNaojoi-G8F1sYaf5hTpLcTvWjRvlA,3596
53
53
  versionhq/tool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  versionhq/tool/cache_handler.py,sha256=iL8FH7X0G-cdT0uhJwzuhLDaadTXOdfybZcDy151-es,1085
@@ -57,8 +57,8 @@ versionhq/tool/composio_tool_vars.py,sha256=FvBuEXsOQUYnN7RTFxT20kAkiEYkxWKkiVtg
57
57
  versionhq/tool/decorator.py,sha256=C4ZM7Xi2gwtEMaSeRo-geo_g_MAkY77WkSLkAuY0AyI,1205
58
58
  versionhq/tool/model.py,sha256=7ccEnje_8LuxLVeog6pL38nToArXQXk4KY7A9hfprDo,12239
59
59
  versionhq/tool/tool_handler.py,sha256=2m41K8qo5bGCCbwMFferEjT-XZ-mE9F0mDUOBkgivOI,1416
60
- versionhq-1.1.11.8.dist-info/LICENSE,sha256=7CCXuMrAjPVsUvZrsBq9DsxI2rLDUSYXR_qj4yO_ZII,1077
61
- versionhq-1.1.11.8.dist-info/METADATA,sha256=VKscq6wLejKxh7fF2p6V9fbgRveRHbzAjVw5KcBwpTg,18672
62
- versionhq-1.1.11.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
63
- versionhq-1.1.11.8.dist-info/top_level.txt,sha256=DClQwxDWqIUGeRJkA8vBlgeNsYZs4_nJWMonzFt5Wj0,10
64
- versionhq-1.1.11.8.dist-info/RECORD,,
60
+ versionhq-1.1.12.1.dist-info/LICENSE,sha256=cRoGGdM73IiDs6nDWKqPlgSv7aR4n-qBXYnJlCMHCeE,1082
61
+ versionhq-1.1.12.1.dist-info/METADATA,sha256=rPZzAQlTUGo_Fh7FUyQFBELbuzxAOqnC9b83z-qvv20,18694
62
+ versionhq-1.1.12.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
63
+ versionhq-1.1.12.1.dist-info/top_level.txt,sha256=DClQwxDWqIUGeRJkA8vBlgeNsYZs4_nJWMonzFt5Wj0,10
64
+ versionhq-1.1.12.1.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- from versionhq.agent.model import Agent
2
- from versionhq.llm.model import DEFAULT_MODEL_NAME
3
-
4
- """
5
- List up agents to be called across the project.
6
- """
7
-
8
- client_manager = Agent(role="Client Manager", goal="communicate with clients on the task progress", llm=DEFAULT_MODEL_NAME)
9
-
10
- task_evaluator = Agent(
11
- role="Task Evaluator",
12
- goal="score the output according to the given evaluation criteria.",
13
- llm=DEFAULT_MODEL_NAME,
14
- llm_config=dict(top_p=0.8, top_k=30, max_tokens=5000, temperature=0.9)
15
- )