Skip to content

Commit 6411e4f

Browse files
Merge pull request #3335 from Agenta-AI/release/v0.72.4
[release] v0.72.4
2 parents 37718c0 + c3eb5b5 commit 6411e4f

File tree

26 files changed

+507
-205
lines changed

26 files changed

+507
-205
lines changed

api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "api"
3-
version = "0.72.3"
3+
version = "0.72.4"
44
description = "Agenta API"
55
authors = [
66
{ name = "Mahmoud Mabrouk", email = "mahmoud@agenta.ai" },

sdk/agenta/sdk/assets.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from typing import Dict, Optional, Tuple
2+
3+
from litellm import cost_calculator
4+
5+
16
supported_llm_models = {
27
"anthropic": [
38
"anthropic/claude-sonnet-4-5",
@@ -206,6 +211,58 @@
206211

207212
providers_list = list(supported_llm_models.keys())
208213

214+
215+
def _get_model_costs(model: str) -> Optional[Tuple[float, float]]:
216+
"""
217+
Get the input and output costs per 1M tokens for a model.
218+
219+
Uses litellm's cost_calculator (same as tracing/inline.py) for consistency.
220+
221+
Args:
222+
model: The model name (e.g., "gpt-4o" or "anthropic/claude-3-opus-20240229")
223+
224+
Returns:
225+
Tuple of (input_cost, output_cost) per 1M tokens, or None if not found.
226+
"""
227+
try:
228+
costs = cost_calculator.cost_per_token(
229+
model=model,
230+
prompt_tokens=1_000_000,
231+
completion_tokens=1_000_000,
232+
)
233+
if costs:
234+
input_cost, output_cost = costs
235+
if input_cost > 0 or output_cost > 0:
236+
return (input_cost, output_cost)
237+
except Exception:
238+
pass
239+
return None
240+
241+
242+
def _build_model_metadata() -> Dict[str, Dict[str, Dict[str, float]]]:
243+
"""
244+
Build metadata dictionary with costs for all supported models.
245+
246+
Returns:
247+
Nested dict: {provider: {model: {"input": cost, "output": cost}}}
248+
"""
249+
metadata: Dict[str, Dict[str, Dict[str, float]]] = {}
250+
251+
for provider, models in supported_llm_models.items():
252+
metadata[provider] = {}
253+
for model in models:
254+
costs = _get_model_costs(model)
255+
if costs:
256+
metadata[provider][model] = {
257+
"input": costs[0],
258+
"output": costs[1],
259+
}
260+
261+
return metadata
262+
263+
264+
model_metadata = _build_model_metadata()
265+
209266
model_to_provider_mapping = {
210267
model: provider
211268
for provider, models in supported_llm_models.items()

sdk/agenta/sdk/middleware/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ async def _parse_variant_ref(
224224
baggage.get("ag.refs.variant.slug")
225225
# ALTERNATIVE
226226
or request.query_params.get("variant_slug")
227+
or body.get("variant_slug")
227228
# LEGACY
228229
or baggage.get("variant_slug")
229230
or request.query_params.get("config")
@@ -234,6 +235,7 @@ async def _parse_variant_ref(
234235
baggage.get("ag.refs.variant.version")
235236
# ALTERNATIVE
236237
or request.query_params.get("variant_version")
238+
or body.get("variant_version")
237239
# LEGACY
238240
or baggage.get("variant_version")
239241
)
@@ -244,7 +246,7 @@ async def _parse_variant_ref(
244246
return Reference(
245247
id=variant_id,
246248
slug=variant_slug,
247-
version=variant_version,
249+
version=str(variant_version) if variant_version is not None else None,
248250
)
249251

250252
async def _parse_environment_ref(

sdk/agenta/sdk/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from starlette.responses import StreamingResponse
99

1010

11-
from agenta.sdk.assets import supported_llm_models
11+
from agenta.sdk.assets import supported_llm_models, model_metadata
1212
from agenta.client.backend.types import AgentaNodesResponse, AgentaNodeDto
1313

1414

@@ -23,7 +23,11 @@ def MCField( # pylint: disable=invalid-name
2323
) -> Field:
2424
# Pydantic 2.12+ no longer allows post-creation mutation of field properties
2525
if isinstance(choices, dict):
26-
json_extra = {"choices": choices, "x-parameter": "grouped_choice"}
26+
json_extra = {
27+
"choices": choices,
28+
"x-parameter": "grouped_choice",
29+
"x-model-metadata": model_metadata,
30+
}
2731
elif isinstance(choices, list):
2832
json_extra = {"choices": choices, "x-parameter": "choice"}
2933
else:

sdk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "agenta"
3-
version = "0.72.3"
3+
version = "0.72.4"
44
description = "The SDK for agenta is an open-source LLMOps platform."
55
readme = "README.md"
66
authors = [

web/ee/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agenta/ee",
3-
"version": "0.72.3",
3+
"version": "0.72.4",
44
"private": true,
55
"engines": {
66
"node": ">=18"

web/oss/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@agenta/oss",
3-
"version": "0.72.3",
3+
"version": "0.72.4",
44
"private": true,
55
"engines": {
66
"node": ">=18"
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import {getEnv} from "@/oss/lib/helpers/dynamicEnv"
22

33
export default function pythonCode(appName: string, env_name: string, apiKey: string): string {
4-
return `
5-
import os
4+
return `import os
65
import agenta as ag
76
8-
os.environ["AGENTA_API_KEY"] = "${apiKey}" # Add your API key here
7+
os.environ["AGENTA_API_KEY"] = "${apiKey}"
98
os.environ["AGENTA_HOST"] = "${getEnv("NEXT_PUBLIC_AGENTA_API_URL")}"
109
1110
ag.init()
1211
config = ag.ConfigManager.get_from_registry(
1312
app_slug="${appName}",
14-
environment_slug="${env_name}"
15-
)
13+
environment_slug="${env_name}",
14+
)
1615
print(config)
1716
`
1817
}

web/oss/src/code_snippets/endpoints/fetch_config/typescript.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const getConfig = async (appName: string, environmentSlug: string) => {
2222
},
2323
}, {
2424
headers: {
25-
'Content-Type': 'application/json',
26-
'Authorization': "ApiKey ${apiKey}", // Add your API key here
25+
'Content-Type': 'application/json',
26+
'Authorization': "ApiKey ${apiKey}",
2727
},
2828
});
2929

web/oss/src/code_snippets/endpoints/fetch_variant/curl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import {getEnv} from "@/oss/lib/helpers/dynamicEnv"
2+
13
export const buildCurlSnippet = (
24
appSlug: string,
35
variantSlug: string,
46
variantVersion: number,
57
apiKey: string,
68
) => {
7-
return `# Fetch configuration by variant
8-
curl -X POST "https://cloud.agenta.ai/api/variants/configs/fetch" \\
9+
return `curl -X POST "${getEnv("NEXT_PUBLIC_AGENTA_API_URL")}/variants/configs/fetch" \\
910
-H "Content-Type: application/json" \\
10-
-H "Authorization: Bearer ${apiKey}" \\
11+
-H "Authorization: ApiKey ${apiKey}" \\
1112
-d '{
1213
"variant_ref": {
1314
"slug": "${variantSlug}",

0 commit comments

Comments
 (0)