{"record":{"id":"bbe7d3a8291e352e","repo":"langchain-ai/deepagents","slug":"error-invalid-agent-name-error-msg","errorCode":null,"errorMessage":"Error: Invalid agent name: {error_msg}","messagePattern":"Error: Invalid agent name: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/skills/commands.py","lineNumber":1228,"sourceCode":"    # The `trust` subcommand manages directory paths, not agent-scoped skills,\n    # so it has no `--agent` and is dispatched before agent validation.\n    if args.skills_command == \"trust\":\n        _trust(args)\n        return\n\n    # validate agent argument\n    if getattr(args, \"agent\", None):\n        is_valid, error_msg = _validate_name(args.agent)\n        if not is_valid:\n            console.print(\n                f\"[bold red]Error:[/bold red] Invalid agent name: {error_msg}\"\n            )\n            console.print(\n                \"[dim]Agent names must only contain letters, numbers, \"\n                \"hyphens, and underscores.[/dim]\",\n                style=theme.MUTED,\n            )\n            raise SystemExit(1)\n\n    output_format = getattr(args, \"output_format\", \"text\")\n\n    # \"ls\" is an argparse alias for \"list\" — argparse stores the alias\n    # as-is in the namespace, so we must match both values.\n    if args.skills_command in {\"list\", \"ls\"}:\n        _list(agent=args.agent, project=args.project, output_format=output_format)\n    elif args.skills_command == \"create\":\n        _create(\n            args.name,\n            agent=args.agent,\n            project=args.project,\n            output_format=output_format,\n        )\n    elif args.skills_command == \"info\":\n        _info(\n            args.name,\n            agent=args.agent,","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/skills/commands.py#L1210-L1246","documentation":"`execute_skills_command` validates the `--agent` argument's name before using it, printing `Error: Invalid agent name: <error_msg>` plus a hint that agent names may only contain letters, numbers, hyphens, and underscores, then exits with status 1. The check prevents invalid characters from reaching paths or configuration keyed by agent name.","triggerScenarios":"Invoking a skills subcommand with `--agent` whose value contains characters outside `[A-Za-z0-9_-]` (spaces, dots, slashes, unicode) so the validation routine produces an `error_msg`.","commonSituations":"Passing an agent display name with spaces instead of its identifier; shell interpolation inserting slashes or dots; copy-pasting an agent label from docs or UI that differs from its internal name.","solutions":["Use only letters, numbers, hyphens, and underscores in the --agent value","Quote the argument in the shell and avoid path-like values (no `/`, `.`, spaces)","List available agents and use the exact internal identifier"],"exampleFix":"// before\n$ dcode skills list --agent \"My Agent.01\"\n# Error: Invalid agent name: ...\n// after\n$ dcode skills list --agent my-agent-01","handlingStrategy":"validation","validationCode":"import re\n\ndef is_valid_agent_name(name: str) -> bool:\n    return bool(re.fullmatch(r'[A-Za-z0-9_-]+', name))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote --agent values in the shell","Use the internal agent identifier, not its display name","Validate names in scripts before invoking the CLI","Stick to letters, digits, hyphens, underscores"],"tags":["cli","validation","argument-parsing"],"backgroundTag":"invalid-identifier","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}