Add prem support for a2a agents

This commit is contained in:
Adil Hafeez 2025-04-25 00:57:13 -07:00
parent 2e346143dd
commit 299f183e66
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
23 changed files with 2544 additions and 16 deletions

View file

@ -1,6 +1,5 @@
use crate::consts::{ARCH_FC_MODEL_NAME, ASSISTANT_ROLE};
use serde::{ser::SerializeMap, Deserialize, Serialize};
use serde_yaml::Value;
use std::{
collections::{HashMap, VecDeque},
fmt::Display,
@ -43,6 +42,8 @@ pub struct FunctionDefinition {
#[derive(Debug, Clone, Deserialize)]
pub struct FunctionParameters {
#[serde(rename = "type")]
pub properties_type: String,
pub properties: HashMap<String, FunctionParameter>,
}
@ -51,7 +52,7 @@ impl Serialize for FunctionParameters {
where
S: serde::Serializer,
{
// select all requried parameters
// select all required parameters
let required: Vec<&String> = self
.properties
.iter()
@ -60,6 +61,7 @@ impl Serialize for FunctionParameters {
.collect();
let mut map = serializer.serialize_map(Some(2))?;
map.serialize_entry("properties", &self.properties)?;
map.serialize_entry("type", &self.properties_type)?;
if !required.is_empty() {
map.serialize_entry("required", &required)?;
}
@ -113,7 +115,7 @@ pub enum ParameterType {
Float,
#[serde(rename = "bool")]
Bool,
#[serde(rename = "str")]
#[serde(rename = "string")]
String,
#[serde(rename = "list")]
List,
@ -189,7 +191,7 @@ pub struct ToolCall {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCallDetail {
pub name: String,
pub arguments: Option<HashMap<String, Value>>,
pub arguments: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]

View file

@ -19,6 +19,37 @@ pub struct Configuration {
pub ratelimits: Option<Vec<Ratelimit>>,
pub tracing: Option<Tracing>,
pub mode: Option<GatewayMode>,
pub agents: HashMap<String, Agent>,
pub tools: HashMap<String, Tool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Agent {
pub name: String,
pub description: String,
pub default_input_modes: Option<Vec<String>>,
pub default_output_modes: Option<Vec<String>>,
pub skills: Option<Vec<Skill>>,
pub model: String,
pub agent_orchestrator_prompt: Option<String>,
pub system_prompt: Option<String>,
pub tools: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Skill {
pub id: String,
pub name: String,
pub description: String,
pub examples: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tool {
pub name: String,
pub description: String,
pub endpoint: Option<EndpointDetails>,
pub parameters: Option<Vec<Parameter>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
@ -260,7 +291,48 @@ impl From<&PromptTarget> for ChatCompletionTool {
function: FunctionDefinition {
name: val.name.clone(),
description: val.description.clone(),
parameters: FunctionParameters { properties },
parameters: FunctionParameters {
properties,
properties_type: "object".to_string(),
},
},
}
}
}
// convert Tool to ChatCompletionTool
impl From<&Tool> for ChatCompletionTool {
fn from(val: &Tool) -> Self {
let properties: HashMap<String, FunctionParameter> = match val.parameters {
Some(ref entities) => {
let mut properties: HashMap<String, FunctionParameter> = HashMap::new();
for entity in entities.iter() {
let param = FunctionParameter {
parameter_type: ParameterType::from(
entity.parameter_type.clone().unwrap_or("str".to_string()),
),
description: entity.description.clone(),
required: entity.required,
enum_values: entity.enum_values.clone(),
default: entity.default.clone(),
format: entity.format.clone(),
};
properties.insert(entity.name.clone(), param);
}
properties
}
None => HashMap::new(),
};
ChatCompletionTool {
tool_type: crate::api::open_ai::ToolType::Function,
function: FunctionDefinition {
name: val.name.clone(),
description: val.description.clone(),
parameters: FunctionParameters {
properties,
properties_type: "object".to_string(),
},
},
}
}

View file

@ -11,7 +11,8 @@ pub const MODEL_SERVER_NAME: &str = "model_server";
pub const ARCH_ROUTING_HEADER: &str = "x-arch-llm-provider";
pub const MESSAGES_KEY: &str = "messages";
pub const ARCH_PROVIDER_HINT_HEADER: &str = "x-arch-llm-provider-hint";
pub const CHAT_COMPLETIONS_PATH: [&str; 2] = ["/v1/chat/completions", "/openai/v1/chat/completions"];
pub const CHAT_COMPLETIONS_PATH: [&str; 2] =
["/v1/chat/completions", "/openai/v1/chat/completions"];
pub const HEALTHZ_PATH: &str = "/healthz";
pub const X_ARCH_STATE_HEADER: &str = "x-arch-state";
pub const X_ARCH_API_RESPONSE: &str = "x-arch-api-response-message";