All files / web/src/components/agents/skills create-skill-view.tsx

59.7% Statements 363/608
78.26% Branches 18/23
57.14% Functions 8/14
59.7% Lines 363/608

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772    1x 1x 1x 1x 1x             1x 1x                 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 56x 56x 56x 56x     56x 30x 3x 30x 56x     56x   56x 56x   56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x   56x   56x                                                                                     56x 1x           1x 1x 1x 1x   56x 56x 56x 56x 56x 56x 3x 53x   56x 56x 56x   56x 3x 3x 3x 3x 3x 3x 3x 3x   3x 3x 3x 3x 3x 3x 3x 3x   3x 3x 3x 3x       56x 56x 56x 56x 56x 56x 56x   56x 56x 56x 56x   56x 56x 56x 56x 56x   56x 56x 56x 56x 67x 67x   67x 67x     67x 67x 67x 67x 67x 67x 67x 67x 67x 10x   10x 10x 67x 67x 67x 67x 67x   56x   56x 56x 56x 56x 60x 60x   60x 60x       60x     60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x   56x   56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x   56x 56x       56x 56x 56x   56x   56x 56x 56x 56x 61x 61x   61x 61x         61x 61x 61x 61x 61x 61x 61x 61x 61x 5x   61x 61x 61x 61x 61x   56x     56x 56x 56x 56x 56x 56x 56x 56x   56x   56x 56x     56x   56x 56x       56x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 56x 56x 56x 56x 56x 56x 56x 56x 56x   56x 56x 56x 56x 56x 56x   56x           56x 56x   56x   56x 56x 56x 56x 56x 56x     56x 56x 56x 56x   56x 56x 56x 56x 56x 56x 56x     56x 56x 56x 56x 56x     56x 56x 56x 56x 56x     56x 56x 56x 56x 56x     56x 53x 53x 53x 53x 53x 53x   53x 53x     53x 53x 53x 53x 53x   56x 56x   56x  
'use client';
 
import { zodResolver } from '@hookform/resolvers/zod';
import { sanitizeUserInput } from '@shared/utils/security';
import { useParams } from '@tanstack/react-router';
import { Button } from '@web/components/ui/button';
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from '@web/components/ui/card';
import { Checkbox } from '@web/components/ui/checkbox';
import {
  Form,
  FormControl,
  FormDescription,
  FormField,
  FormItem,
  FormLabel,
  FormMessage,
} from '@web/components/ui/form';
import { Input } from '@web/components/ui/input';
import { PageHeader } from '@web/components/ui/page-header';
import { Slider } from '@web/components/ui/slider';
import { Textarea } from '@web/components/ui/textarea';
import { usePermissiveNavigate } from '@web/hooks/use-permissive-navigate';
import { useAgents } from '@web/providers/agents';
import { useSkills } from '@web/providers/skills';
import { Bot, ChevronDown, ChevronUp, Plus, Wrench, X } from 'lucide-react';
import * as React from 'react';
import { useForm } from 'react-hook-form';
import { z } from 'zod';
 
// Form field constraints
const CONSTRAINTS = {
  name: { min: 3, max: 100 },
  description: { min: 25, max: 10000 },
  configuration_count: { min: 1, max: 25 },
  clustering_interval: { min: 1, max: 1000 },
  reflection_min_requests_per_arm: { min: 1, max: 1000 },
  exploration_temperature: { min: 0.1, max: 10.0 },
} as const;
 
// Common template variable suggestions
const SUGGESTED_TEMPLATE_VARIABLES = [
  {
    value: 'datetime',
    description: 'Current date/time',
  },
  {
    value: 'user_id',
    description: 'User identifier',
  },
  {
    value: 'context',
    description: 'Additional context',
  },
] as const;
 
const CreateSkillFormSchema = z
  .object({
    name: z
      .string()
      .min(CONSTRAINTS.name.min, 'Skill name must be at least 3 characters')
      .max(CONSTRAINTS.name.max, 'Skill name must be less than 100 characters')
      .regex(/^[a-z0-9_-]+$/, {
        message:
          'Skill name must only contain lowercase letters, numbers, underscores, and hyphens',
      }),
    description: z
      .string()
      .min(
        CONSTRAINTS.description.min,
        'Description must be at least 25 characters',
      )
      .max(
        CONSTRAINTS.description.max,
        'Description must be less than 10000 characters',
      ),
    optimize: z.boolean(),
    configuration_count: z
      .number()
      .int()
      .min(
        CONSTRAINTS.configuration_count.min,
        'Configuration count must be at least 1',
      )
      .max(
        CONSTRAINTS.configuration_count.max,
        'Configuration count cannot exceed 25',
      ),
    clustering_interval: z
      .number()
      .int()
      .min(
        CONSTRAINTS.clustering_interval.min,
        'Clustering interval must be at least 1',
      )
      .max(
        CONSTRAINTS.clustering_interval.max,
        'Clustering interval cannot exceed 1000',
      ),
    reflection_min_requests_per_arm: z
      .number()
      .int()
      .min(
        CONSTRAINTS.reflection_min_requests_per_arm.min,
        'Min requests per arms must be at least 1',
      )
      .max(
        CONSTRAINTS.reflection_min_requests_per_arm.max,
        'Requests per arms cannot exceed 1000',
      ),
    exploration_temperature: z
      .number()
      .min(
        CONSTRAINTS.exploration_temperature.min,
        'Exploration temperature must be at least 0.1',
      )
      .max(
        CONSTRAINTS.exploration_temperature.max,
        'Exploration temperature cannot exceed 10.0',
      ),
    allowed_template_variables: z.array(z.string()),
  })
  .strict();
 
type CreateSkillFormData = z.infer<typeof CreateSkillFormSchema>;
 
export function CreateSkillView(): React.ReactElement {
  const { agents, selectedAgent } = useAgents();
  const { createSkill, isCreating } = useSkills();
  const navigate = usePermissiveNavigate();
  const { agentName } = useParams({ strict: false }) as { agentName?: string };
 
  // Find agent by name from URL parameter
  const agentFromUrl = React.useMemo(() => {
    if (!agentName || !agents.length) return null;
    const decodedAgentName = decodeURIComponent(agentName);
    return agents.find((agent) => agent.name === decodedAgentName) || null;
  }, [agentName, agents]);
 
  // Use agent from URL if available, otherwise use selected agent
  const currentAgent = agentFromUrl || selectedAgent;
 
  const [showAdvanced, setShowAdvanced] = React.useState(false);
  const [newVariableName, setNewVariableName] = React.useState('');
 
  const form = useForm<CreateSkillFormData>({
    resolver: zodResolver(CreateSkillFormSchema),
    defaultValues: {
      name: '',
      description: '',
      optimize: true,
      configuration_count: 3,
      clustering_interval: 100,
      reflection_min_requests_per_arm: 8,
      exploration_temperature: 3.0,
      allowed_template_variables: [],
    },
  });
 
  const optimizeEnabled = form.watch('optimize');
 
  const onSubmit = async (data: CreateSkillFormData) => {
    if (!currentAgent) {
      console.error('No agent selected');
      return;
    }
 
    try {
      const skillParams = {
        agent_id: currentAgent.id,
        name: data.name,
        description: sanitizeUserInput(data.description),
        metadata: {},
        optimize: data.optimize,
        configuration_count: data.configuration_count,
        clustering_interval: data.clustering_interval,
        reflection_min_requests_per_arm: data.reflection_min_requests_per_arm,
        exploration_temperature: data.exploration_temperature,
        allowed_template_variables: data.allowed_template_variables,
      };
 
      const newSkill = await createSkill(skillParams);
 
      // Reset form after successful creation
      form.reset();
 
      // Navigate to setup page to add models and evaluations, replacing history to prevent back button going to create page
      if (agentName) {
        navigate({
          to: '/agents/$agentName/skills/$skillName/setup',
          params: { agentName, skillName: newSkill.name },
          replace: true,
        });
      } else {
        navigate({ to: '/agents', replace: true });
      }
    } catch (error) {
      console.error('Error creating skill:', error);
      // Error is already handled by the skills provider
    }
  };
 
  // No need to update form since agent is fixed
 
  const handleBack = () => {
    if (agentName) {
      navigate({
        to: '/agents/$agentName',
        params: { agentName },
        search: { skip_create: 'true' },
      });
    } else {
      navigate({ to: '/agents' });
    }
  };
 
  return (
    <>
      <PageHeader
        title="Create New Skill"
        description={
          currentAgent
            ? `Define a new capability for ${currentAgent.name}`
            : 'Define a new capability for this agent'
        }
        onBack={handleBack}
      />
      <div className="container mx-auto py-6 max-w-2xl">
        {/* Agent Context Card */}
        {currentAgent && (
          <Card className="mb-6 border-primary/20 bg-primary/5">
            <CardContent className="p-4">
              <div className="flex items-center gap-3">
                <div className="bg-primary/10 p-2 rounded-lg">
                  <Bot className="h-5 w-5 text-primary" />
                </div>
                <div>
                  <div className="text-sm text-muted-foreground">
                    Creating skill for
                  </div>
                  <div className="font-semibold text-lg">
                    {currentAgent.name}
                  </div>
                  {currentAgent.description && (
                    <div className="text-sm text-muted-foreground mt-1">
                      {currentAgent.description}
                    </div>
                  )}
                </div>
              </div>
            </CardContent>
          </Card>
        )}
 
        {/* Main Form Card */}
        <Card className="shadow-lg">
          <CardHeader className="pb-6">
            <div className="flex items-center gap-3">
              <Wrench className="h-5 w-5 text-primary" />
              <div>
                <CardTitle>Skill Optimization</CardTitle>
                <CardDescription>
                  Define your skill's basic information and purpose
                </CardDescription>
              </div>
            </div>
          </CardHeader>
 
          <CardContent>
            <Form {...form}>
              <form
                onSubmit={form.handleSubmit(onSubmit)}
                className="space-y-6"
              >
                <FormField
                  control={form.control}
                  name="name"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel className="text-base font-medium">
                        Skill Name
                      </FormLabel>
                      <FormDescription>
                        Choose a descriptive name using only lowercase letters,
                        numbers, underscores, and hyphens.
                      </FormDescription>
                      <FormControl>
                        <Input
                          placeholder="e.g., data-analysis, email_templates, code-review"
                          className="h-11"
                          pattern="[a-z0-9_-]+"
                          title="Only lowercase letters, numbers, underscores, and hyphens are allowed"
                          {...field}
                          onChange={(e) => {
                            field.onChange(e);
                            // Trigger validation on every change
                            form.trigger('name');
                          }}
                          disabled={isCreating}
                        />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
 
                <FormField
                  control={form.control}
                  name="description"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel className="text-base font-medium">
                        Description (required)
                      </FormLabel>
                      <FormDescription>
                        Provide additional context about the skill's
                        functionality, use cases, and any special requirements
                        or limitations (minimum 25 characters). This description
                        is <span className="font-bold">crucial</span> so that
                        the system can create accurate system prompts and
                        evaluations for the skill.
                      </FormDescription>
                      <FormControl>
                        <Textarea
                          placeholder="Describe what this skill does, how it works, and when to use it. For example: 'Analyzes datasets and generates statistical reports with visualizations. Useful for data-driven decision making and trend analysis.'"
                          className="resize-none min-h-[120px]"
                          {...field}
                          disabled={isCreating}
                        />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
 
                <FormField
                  control={form.control}
                  name="optimize"
                  render={({ field }) => (
                    <FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4">
                      <FormControl>
                        <Checkbox
                          checked={field.value}
                          onCheckedChange={field.onChange}
                          disabled={isCreating}
                        />
                      </FormControl>
                      <div className="space-y-1 leading-none">
                        <FormLabel className="text-base font-medium">
                          Enable Optimization
                        </FormLabel>
                        <FormDescription>
                          Automatically optimize this skill by testing multiple
                          configurations and prompts to find the best
                          performance. Disable to use default settings.
                        </FormDescription>
                      </div>
                    </FormItem>
                  )}
                />
 
                <FormField
                  control={form.control}
                  name="configuration_count"
                  render={({ field }) => (
                    <FormItem>
                      <FormLabel className="text-base font-medium">
                        Number of Partitions
                      </FormLabel>
                      <FormDescription>
                        Each request to the skill will be routed to one of the
                        partitions. Each partition has its own optimal
                        configuration consisting of its own model, system
                        prompt, and hyperparameters.
                      </FormDescription>
                      <FormControl>
                        <Input
                          type="number"
                          min={CONSTRAINTS.configuration_count.min}
                          max={CONSTRAINTS.configuration_count.max}
                          className="h-11 max-w-xs"
                          {...field}
                          onChange={(e) =>
                            field.onChange(Number(e.target.value))
                          }
                          disabled={isCreating || !optimizeEnabled}
                        />
                      </FormControl>
                      <FormMessage />
                    </FormItem>
                  )}
                />
 
                {/* Advanced Settings Toggle */}
                {optimizeEnabled && (
                  <div className="pt-2">
                    <Button
                      type="button"
                      variant="ghost"
                      size="sm"
                      onClick={() => setShowAdvanced(!showAdvanced)}
                      className="w-full justify-between text-muted-foreground hover:text-foreground"
                    >
                      <span className="text-sm font-medium">
                        Advanced Settings
                      </span>
                      {showAdvanced ? (
                        <ChevronUp className="h-4 w-4" />
                      ) : (
                        <ChevronDown className="h-4 w-4" />
                      )}
                    </Button>
                  </div>
                )}
 
                {/* Advanced Settings Section */}
                {showAdvanced && (
                  <>
                    <FormField
                      control={form.control}
                      name="clustering_interval"
                      render={({ field }) => (
                        <FormItem>
                          <FormLabel className="text-base font-medium">
                            Skill Partitioning Interval
                          </FormLabel>
                          <FormDescription>
                            The number of requests between running the
                            partitioning algorithm. The algorithm uses all the
                            requests since the algorithm was last ran to
                            partition the skill semantically.
                          </FormDescription>
                          <FormControl>
                            <Input
                              type="number"
                              min={CONSTRAINTS.clustering_interval.min}
                              max={CONSTRAINTS.clustering_interval.max}
                              className="h-11 max-w-xs"
                              {...field}
                              onChange={(e) =>
                                field.onChange(Number(e.target.value))
                              }
                              disabled={isCreating || !optimizeEnabled}
                            />
                          </FormControl>
                          <FormMessage />
                        </FormItem>
                      )}
                    />
 
                    <FormField
                      control={form.control}
                      name="reflection_min_requests_per_arm"
                      render={({ field }) => (
                        <FormItem>
                          <FormLabel className="text-base font-medium">
                            Minimum Requests Per Arm Reflection Threshold
                          </FormLabel>
                          <FormDescription>
                            Ensures that all configurations in a partition have
                            each received at least this number of requests
                            before generating new system prompts. This helps
                            make sure that the system has better data to create
                            new system prompts on.
                          </FormDescription>
                          <FormControl>
                            <Input
                              type="number"
                              min={
                                CONSTRAINTS.reflection_min_requests_per_arm.min
                              }
                              max={
                                CONSTRAINTS.reflection_min_requests_per_arm.max
                              }
                              className="h-11 max-w-xs"
                              {...field}
                              onChange={(e) =>
                                field.onChange(Number(e.target.value))
                              }
                              disabled={isCreating || !optimizeEnabled}
                            />
                          </FormControl>
                          <FormMessage />
                        </FormItem>
                      )}
                    />
 
                    <FormField
                      control={form.control}
                      name="exploration_temperature"
                      render={({ field }) => (
                        <FormItem>
                          <div className="flex items-center justify-between">
                            <FormLabel className="text-base font-medium">
                              Exploration Temperature
                            </FormLabel>
                            <span className="text-sm font-mono text-muted-foreground">
                              {field.value.toFixed(1)}
                            </span>
                          </div>
                          <FormDescription>
                            Controls how aggressively the system explores
                            different configurations. Higher values make the
                            system take more risks and try suboptimal
                            configurations more often. Lower values make it
                            stick to known good configurations.
                          </FormDescription>
                          <FormControl>
                            <Slider
                              min={CONSTRAINTS.exploration_temperature.min}
                              max={CONSTRAINTS.exploration_temperature.max}
                              step={0.1}
                              value={[field.value]}
                              onValueChange={(values) =>
                                field.onChange(values[0])
                              }
                              disabled={isCreating || !optimizeEnabled}
                              className="mt-2"
                            />
                          </FormControl>
                          <FormMessage />
                        </FormItem>
                      )}
                    />
 
                    <FormField
                      control={form.control}
                      name="allowed_template_variables"
                      render={({ field }) => (
                        <FormItem>
                          <FormLabel className="text-base font-medium">
                            Template Variables
                          </FormLabel>
                          <FormDescription>
                            Define variable names that can be used in system
                            prompts. Provide values via{' '}
                            <code className="text-xs">
                              system_prompt_variables
                            </code>
                            .
                          </FormDescription>
 
                          {/* Current variables */}
                          {field.value && field.value.length > 0 && (
                            <div className="space-y-2 pt-2">
                              {field.value.map((varName) => (
                                <div
                                  key={varName}
                                  className="flex items-center justify-between rounded-md border border-border bg-muted/50 px-3 py-2"
                                >
                                  <code className="text-sm font-mono">
                                    {varName}
                                  </code>
                                  <Button
                                    type="button"
                                    variant="ghost"
                                    size="sm"
                                    onClick={() => {
                                      field.onChange(
                                        field.value.filter(
                                          (v) => v !== varName,
                                        ),
                                      );
                                    }}
                                    disabled={isCreating || !optimizeEnabled}
                                    className="h-6 w-6 p-0"
                                  >
                                    <X className="h-3 w-3" />
                                  </Button>
                                </div>
                              ))}
                            </div>
                          )}
 
                          {/* Add new variable */}
                          <div className="flex gap-2 pt-2">
                            <Input
                              placeholder="variable_name"
                              value={newVariableName}
                              onChange={(e) =>
                                setNewVariableName(
                                  e.target.value
                                    .toLowerCase()
                                    .replace(/[^a-z0-9_]/g, ''),
                                )
                              }
                              onKeyDown={(e) => {
                                if (e.key === 'Enter') {
                                  e.preventDefault();
                                  if (
                                    newVariableName &&
                                    !field.value.includes(newVariableName)
                                  ) {
                                    field.onChange([
                                      ...field.value,
                                      newVariableName,
                                    ]);
                                    setNewVariableName('');
                                  }
                                }
                              }}
                              disabled={isCreating || !optimizeEnabled}
                              className="flex-1 font-mono text-sm"
                            />
                            <Button
                              type="button"
                              variant="outline"
                              size="sm"
                              onClick={() => {
                                if (
                                  newVariableName &&
                                  !field.value.includes(newVariableName)
                                ) {
                                  field.onChange([
                                    ...field.value,
                                    newVariableName,
                                  ]);
                                  setNewVariableName('');
                                }
                              }}
                              disabled={
                                isCreating ||
                                !optimizeEnabled ||
                                !newVariableName ||
                                field.value.includes(newVariableName)
                              }
                            >
                              <Plus className="h-4 w-4" />
                            </Button>
                          </div>
 
                          {/* Suggestions */}
                          {SUGGESTED_TEMPLATE_VARIABLES.some(
                            (v) => !field.value.includes(v.value),
                          ) && (
                            <div className="pt-2">
                              <p className="text-xs text-muted-foreground mb-2">
                                Quick add:
                              </p>
                              <div className="flex flex-wrap gap-2">
                                {SUGGESTED_TEMPLATE_VARIABLES.filter(
                                  (v) => !field.value.includes(v.value),
                                ).map((variable) => (
                                  <Button
                                    key={variable.value}
                                    type="button"
                                    variant="outline"
                                    size="sm"
                                    onClick={() => {
                                      field.onChange([
                                        ...field.value,
                                        variable.value,
                                      ]);
                                    }}
                                    disabled={isCreating || !optimizeEnabled}
                                    className="h-7 text-xs"
                                  >
                                    <Plus className="h-3 w-3 mr-1" />
                                    {variable.value}
                                  </Button>
                                ))}
                              </div>
                            </div>
                          )}
 
                          <FormMessage />
                        </FormItem>
                      )}
                    />
                  </>
                )}
 
                {/* Action Buttons */}
                <div className="flex gap-3 pt-4">
                  <Button
                    type="button"
                    variant="outline"
                    size="lg"
                    onClick={handleBack}
                    disabled={isCreating}
                    className="flex-1"
                  >
                    Cancel
                  </Button>
                  <Button
                    type="submit"
                    size="lg"
                    disabled={isCreating || !currentAgent}
                    className="flex-1"
                  >
                    {isCreating ? (
                      <>
                        <Wrench className="mr-2 h-4 w-4 animate-pulse" />
                        Creating Skill...
                      </>
                    ) : (
                      <>
                        <Wrench className="mr-2 h-4 w-4" />
                        Create Skill
                      </>
                    )}
                  </Button>
                </div>
              </form>
            </Form>
          </CardContent>
        </Card>
 
        {/* Tips Card */}
        <Card className="mt-6 border-primary/20 bg-primary/5">
          <CardHeader className="pb-4">
            <CardTitle className="text-lg flex items-center gap-2">
              <Wrench className="h-5 w-5 text-primary" />
              Tips for Creating Effective Skills
            </CardTitle>
          </CardHeader>
          <CardContent className="space-y-3">
            <div className="text-sm space-y-2">
              <p className="flex items-start gap-2">
                <span className="text-primary font-medium">•</span>
                <span>
                  Use specific, actionable names that clearly describe what the
                  skill accomplishes
                </span>
              </p>
              <p className="flex items-start gap-2">
                <span className="text-primary font-medium">•</span>
                <span>
                  Include implementation details, required inputs, and expected
                  outputs in the description
                </span>
              </p>
              <p className="flex items-start gap-2">
                <span className="text-primary font-medium">•</span>
                <span>
                  You can always edit these details later from the skills
                  management page
                </span>
              </p>
            </div>
          </CardContent>
        </Card>
 
        {/* No Agent Warning */}
        {!currentAgent && (
          <Card className="mt-6 border-yellow-200 bg-yellow-50 dark:border-yellow-800 dark:bg-yellow-900/20">
            <CardContent className="p-4">
              <div className="flex items-center gap-2">
                <Wrench className="h-5 w-5 text-yellow-600 dark:text-yellow-400" />
                <div>
                  <h4 className="text-sm font-medium text-yellow-800 dark:text-yellow-200">
                    Agent not found
                  </h4>
                  <p className="text-sm text-yellow-700 dark:text-yellow-300 mt-1">
                    Unable to find the specified agent. Please ensure the agent
                    exists and try again.
                  </p>
                </div>
              </div>
            </CardContent>
          </Card>
        )}
      </div>
    </>
  );
}