Skip to content

Mock Provider

The Mock provider is designed for testing purposes, allowing you to develop and test agents without making actual API calls or incurring costs. It returns predictable responses by converting input text to pig latin and generates random embeddings.

Configuration

Basic Setup

Configure the Mock provider in your agent:

ruby
class MockAgent < ApplicationAgent
  generate_with :mock

  # @return [ActiveAgent::Generation]
  def ask
    prompt(message: params[:message])
  end
end

Basic Usage Example

ruby
response = MockAgent.with(message: "What is ActiveAgent?").ask.generate_now
Response Example

Configuration File

Set up Mock provider in config/active_agent.yml:

yaml
mock: &mock
  service: "Mock"
  model: "mock-model"

Environment Variables

No environment variables are required for the Mock provider. It doesn't make external API calls.

Provider-Specific Parameters

Required Parameters

  • service - Must be set to "Mock"
  • model - Any string value (e.g., "mock-model") - not used functionally

Optional Parameters

  • instructions - System instructions (passed through but not enforced)
  • stream - Enable streaming simulation (boolean, default: false)

The Mock provider accepts most standard parameters for compatibility but doesn't enforce them:

  • temperature, top_p, max_tokens - Accepted but ignored
  • response_format - Accepted but not validated or enforced
  • Tool/function definitions - Accepted but tools won't be called

Mock-Specific Features

Pig Latin Responses

The Mock provider converts user messages to pig latin for predictable, deterministic output:

ruby
test "converts input to pig latin" do
  response = MockAgent.with(message: "Hello world").ask.generate_now

  doc_example_output(response)

  assert response.success?
  # Mock provider converts to pig latin
  assert_includes response.message.content.downcase, "ello"
end
Response Example

Conversion Rules:

  • Words starting with vowels: add "way" to the end ("apple" → "appleway")
  • Words starting with consonants: move consonants to end and add "ay" ("hello" → "ellohay")
  • Preserves punctuation and capitalization

Offline Development

Work on your application without network connectivity:

ruby
test "works offline without API calls" do
  # Mock provider doesn't make network requests
  response = MockAgent.with(message: "Offline test").ask.generate_now

  doc_example_output(response)

  assert response.success?
  assert_not_nil response.message.content
end
Response Example

Response Structure

Mock responses follow the same structure as real providers for seamless testing:

ruby
test "returns proper response structure" do
  response = MockAgent.with(message: "Test message").ask.generate_now

  doc_example_output(response)

  assert_equal "assistant", response.message.role
  assert_not_nil response.raw_response
  assert_not_nil response.message.content
end
Response Example

Limitations

No Real AI Responses

The Mock provider doesn't use actual AI models. Responses are deterministic pig latin transformations, not intelligent completions.

No Tool Calling

The Mock provider doesn't support function/tool calling. Tools defined in agents using the Mock provider will not be invoked.

Limited Structured Output

The Mock provider accepts structured output parameters but doesn't validate or enforce schemas. Responses will still be pig latin text, not structured JSON.