/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/forms/SubAgentsTab.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import { useState, useEffect } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Agent } from "@/types/agent"; import { listAgents } from "@/services/agentService"; import { Loader2, Search, X } from "lucide-react"; interface SubAgentsTabProps { values: Partial; onChange: (values: Partial) => void; getAgentNameById: (id: string) => string; editingAgentId?: string; clientId: string; } export function SubAgentsTab({ values, onChange, getAgentNameById, editingAgentId, clientId, }: SubAgentsTabProps) { const [availableAgents, setAvailableAgents] = useState([]); const [isLoading, setIsLoading] = useState(false); const [search, setSearch] = useState(""); // Get folder ID from current agent const folderId = values.folder_id; useEffect(() => { loadAgents(); }, [clientId, folderId, editingAgentId]); const loadAgents = async () => { if (!clientId) return; setIsLoading(true); try { const res = await listAgents( clientId, 0, 100, folderId || undefined ); // Filter out the current agent to avoid self-reference const filteredAgents = res.data.filter(agent => agent.id !== editingAgentId ); setAvailableAgents(filteredAgents); } catch (error) { console.error("Error loading agents:", error); } finally { setIsLoading(false); } }; const handleAddSubAgent = (agentId: string) => { if (!values.config?.sub_agents?.includes(agentId)) { onChange({ ...values, config: { ...values.config, sub_agents: [...(values.config?.sub_agents || []), agentId], }, }); } }; const handleRemoveSubAgent = (agentId: string) => { onChange({ ...values, config: { ...values.config, sub_agents: values.config?.sub_agents?.filter((id) => id !== agentId) || [], }, }); }; const filteredAgents = availableAgents.filter(agent => agent.name.toLowerCase().includes(search.toLowerCase()) ); return (

Sub-Agents

{values.config?.sub_agents?.length || 0} sub-agents selected

Select the agents that will be used as sub-agents.

{values.config?.sub_agents && values.config.sub_agents.length > 0 ? (

Selected sub-agents:

{values.config.sub_agents.map((agentId) => ( {getAgentNameById(agentId)} ))}
) : (
No sub-agents selected
)}

Available agents:

setSearch(e.target.value)} className="pl-9 bg-[#1a1a1a] border-[#444] text-white" /> {search && ( )}
{isLoading ? (
Loading agents...
) : (
{filteredAgents.length === 0 ? (
{search ? `No agents found matching "${search}"` : "No other agents found in this folder"}
) : ( filteredAgents.map((agent) => (
{agent.name} {agent.type === "llm" ? "LLM Agent" : agent.type === "a2a" ? "A2A Agent" : agent.type === "sequential" ? "Sequential Agent" : agent.type === "parallel" ? "Parallel Agent" : agent.type === "loop" ? "Loop Agent" : agent.type === "workflow" ? "Workflow Agent" : agent.type === "task" ? "Task Agent" : agent.type}
)) )}
)}
); }