Skip to main content

Troubleshooting

This page covers common errors you may encounter when using AgentMark and how to resolve them.

Connection & Authentication Errors

AGENTMARK_API_KEY not set

Error: Error: AGENTMARK_API_KEY environment variable is not set Cause: You’re using ApiLoader.cloud() but haven’t configured your API key. Solution:
  1. Get your API key from AgentMark Dashboard
  2. Add it to your .env file:
    AGENTMARK_API_KEY=your-api-key-here
    AGENTMARK_APP_ID=your-app-id-here
    
  3. Restart your development server

AGENTMARK_APP_ID not set

Error: Error: AGENTMARK_APP_ID environment variable is not set Cause: Cloud loader requires both API key and App ID. Solution:
  1. Find your App ID in AgentMark Dashboard
  2. Add to .env:
    AGENTMARK_APP_ID=your-app-id-here
    

Loader connection failed

Error: Error: connect ECONNREFUSED 127.0.0.1:9418 Cause: The local development server isn’t running. Solution:
  1. Start the dev server in a separate terminal:
    agentmark dev
    
  2. Verify it’s running at http://localhost:9418
  3. If using a custom port, update your loader:
    ApiLoader.local({ baseUrl: "http://localhost:YOUR_PORT" })
    

Invalid API key

Error: Error: 401 Unauthorized - Invalid API key Cause: The API key is incorrect or has been revoked. Solution:
  1. Verify your API key in the dashboard
  2. Generate a new key if needed
  3. Update your .env file with the new key

Model Errors

Model not found / not registered

Error: Error: Model "gpt-4o" is not registered in the model registry Cause: The model name in your prompt frontmatter isn’t registered in your client. Solution:
  1. Check the model name in your prompt:
    text_config:
      model_name: gpt-4o  # This must be registered
    
  2. Register the model in agentmark.client.ts:
    const modelRegistry = new VercelAIModelRegistry()
      .registerModels(["gpt-4o"], (name) => openai(name));
    

Provider API key missing

Error: Error: OpenAI API key is missing or ANTHROPIC_API_KEY not set Cause: The AI provider’s API key isn’t configured. Solution: Add the provider’s API key to your .env:
# OpenAI
OPENAI_API_KEY=sk-...

# Anthropic
ANTHROPIC_API_KEY=sk-ant-...

# Google
GOOGLE_GENERATIVE_AI_API_KEY=...

Rate limit exceeded

Error: Error: 429 Too Many Requests - Rate limit exceeded Cause: You’ve exceeded the provider’s rate limits. Solution:
  1. Wait and retry (most SDKs have built-in retry logic)
  2. Reduce request frequency
  3. Consider upgrading your provider plan
  4. Use multiple API keys with rotation

Model not available in region

Error: Error: Model is not available in your region Cause: Some models have regional restrictions. Solution:
  1. Check provider documentation for model availability
  2. Use an alternative model
  3. Consider using a VPN or different deployment region

Tool Errors

Tool not available

Error: Error: Tool "search_knowledgebase" is not registered Cause: The tool referenced in your prompt isn’t registered in the tool registry. Solution:
  1. Check the tool name in your prompt:
    text_config:
      tools:
        - search_knowledgebase  # This must be registered
    
  2. Register the tool in agentmark.client.ts:
    const toolRegistry = new VercelAIToolRegistry()
      .register("search_knowledgebase", async ({ query }) => {
        return { results: await search(query) };
      });
    

Tool execution failed

Error: Error: Tool execution failed: Cannot read property 'x' of undefined Cause: The tool function threw an error, often due to missing or malformed input. Solution:
  1. Add input validation to your tool:
    .register("my_tool", async ({ param }) => {
      if (!param) {
        throw new Error("param is required");
      }
      // ... tool logic
    });
    
  2. Check the tool’s parameter schema matches the prompt definition

MCP Server Errors

MCP server not connecting

Error: Error: Failed to connect to MCP server "docs" Cause: The MCP server configuration is incorrect or the server isn’t running. Solution:
  1. For stdio servers, verify the command works:
    npx -y @modelcontextprotocol/server-filesystem ./data
    
  2. For URL servers, verify the endpoint is accessible:
    curl https://your-mcp-server.com/mcp
    
  3. Check environment variables are set:
    mcpServers: {
      docs: {
        url: "env(MCP_SERVER_URL)",  // Is MCP_SERVER_URL set?
      }
    }
    

MCP tool not found

Error: Error: Tool "web-search" not found on MCP server "docs" Cause: The tool name doesn’t exist on the MCP server. Solution:
  1. List available tools from the server (check server documentation)
  2. Verify the tool name in your prompt:
    tools:
      search: mcp://docs/web-search  # Is "web-search" correct?
    
  3. Use wildcard to import all tools:
    tools:
      all: mcp://docs/*
    

Prompt Errors

Prompt not found

Error: Error: Prompt not found: greeting.prompt.mdx Cause: The prompt file doesn’t exist or the path is incorrect. Solution:
  1. Check the file exists at the expected path
  2. Verify the path in loadTextPrompt():
    // Relative to agentmarkPath in agentmark.json
    await client.loadTextPrompt("greeting.prompt.mdx");
    
    // Or with subdirectory
    await client.loadTextPrompt("helpers/greeting.prompt.mdx");
    
  3. Run agentmark build to verify all prompts are valid

Invalid frontmatter

Error: Error: Invalid frontmatter in prompt file Cause: YAML syntax error in the prompt’s frontmatter. Solution:
  1. Validate YAML syntax (check for proper indentation, colons, quotes)
  2. Common issues:
    # Wrong - missing space after colon
    model_name:gpt-4o
    
    # Correct
    model_name: gpt-4o
    
    # Wrong - improper nesting
    text_config:
    model_name: gpt-4o
    
    # Correct
    text_config:
      model_name: gpt-4o
    

Template syntax error

Error: Error: Unexpected token in template Cause: Invalid TemplateDX syntax in the prompt body. Solution:
  1. Check for unclosed tags:
    {# Wrong - unclosed if #}
    {% if condition %}
      Content here
    
    {# Correct #}
    {% if condition %}
      Content here
    {% endif %}
    
  2. Verify variable syntax: {props.name} not {{props.name}}
  3. See TemplateDX Syntax for reference

Experiment & Dataset Errors

Dataset file not found

Error: Error: Dataset file not found: ./datasets/test.jsonl Cause: The dataset path in test_settings doesn’t exist. Solution:
  1. Check the path in your prompt:
    test_settings:
      dataset: ./datasets/test.jsonl  # Is this path correct?
    
  2. Paths are relative to the prompt file location
  3. Create the dataset file if it doesn’t exist

Invalid dataset format

Error: Error: Invalid JSON on line 3 of dataset Cause: The JSONL file has malformed JSON. Solution:
  1. Each line must be valid JSON:
    {"input": {"name": "Alice"}, "expected": "Hello Alice"}
    {"input": {"name": "Bob"}, "expected": "Hello Bob"}
    
  2. Validate with: cat dataset.jsonl | jq -c '.'
  3. Check for trailing commas or missing quotes

Eval function not registered

Error: Error: Eval "exact_match" is not registered Cause: The evaluation referenced in test_settings isn’t registered. Solution:
  1. Register the eval in agentmark.client.ts:
    const evalRegistry = new EvalRegistry()
      .register("exact_match", ({ output, expectedOutput }) => ({
        score: output === expectedOutput ? 1 : 0,
        passed: output === expectedOutput,
      }));
    
  2. Pass evalRegistry to createAgentMarkClient()

Type Errors

Type mismatch after schema change

Error: TypeScript errors after modifying prompt schemas Cause: Generated types are out of date. Solution:
  1. Regenerate types:
    agentmark generate-types --root-dir ./agentmark > agentmark.types.ts
    
  2. Or use the build command:
    agentmark build
    

Props type error

Error: Argument of type '{ name: string }' is not assignable to parameter Cause: Props don’t match the prompt’s input_schema. Solution:
  1. Check the prompt’s input schema:
    input_schema:
      type: object
      properties:
        name: { type: string }
        age: { type: number }  # Required but missing
      required: [name, age]
    
  2. Provide all required props:
    await prompt.format({
      props: { name: "Alice", age: 30 }
    });
    

CLI Errors

agentmark command not found

Error: command not found: agentmark Cause: CLI not installed globally or not in PATH. Solution:
  1. Install globally:
    npm install -g @agentmark-ai/cli
    
  2. Or use npx:
    npx @agentmark-ai/cli dev
    
  3. Or use package.json scripts:
    {
      "scripts": {
        "dev": "agentmark dev"
      }
    }
    

Port already in use

Error: Error: listen EADDRINUSE: address already in use :::9418 Cause: Another process is using the port. Solution:
  1. Use a different port:
    agentmark dev --api-port 9500
    
  2. Or kill the existing process:
    # Find the process
    lsof -i :9418
    
    # Kill it
    kill -9 <PID>
    

Still Having Issues?

If you’re still experiencing problems:
  1. Check the logs - Run with DEBUG=agentmark:* for verbose output:
    DEBUG=agentmark:* agentmark dev
    
  2. Update packages - Ensure you’re on the latest versions:
    npm update @agentmark-ai/cli @agentmark-ai/ai-sdk-v5-adapter
    
  3. Ask the community - Join our Discord for help
  4. Report a bug - Open an issue on GitHub

Have Questions?

We’re here to help! Choose the best way to reach us: