Ollama × OpenClaw: Creating Business-Specific AI Models with Modelfile
This article provides a detailed explanation of how to create business-specific custom AI models using Ollama's Modelfile feature and deploy them with OpenClaw. We cover practical techniques including prompt engineering, parameter tuning, importing GGUF format models, and A/B testing through multi-agent routing.
Benefits of Creating Custom Models with Modelfile
General-purpose LLMs can handle diverse tasks, but they are not optimized for specific business needs, which can result in response quality and tone that don't match corporate requirements. Ollama's Modelfile feature allows you to customize system prompts, parameters, and templates based on existing models and save them as new models. This makes it easy to create business-specific AI for legal consulting, medical advice, technical support, sales assistance, and more. Since Modelfiles are text files, version control is easy, and they can be shared and reviewed among teams. Combined with OpenClaw, custom models can be instantly deployed across multiple channels like LINE, Slack, and Discord. Companies in Shinagawa-ku and Ota-ku are building AI models that reflect industry-specific terminology and response styles to improve customer satisfaction.
Basic Modelfile Syntax and Structure
A Modelfile consists of four main directives. `FROM` specifies the base model (e.g., `FROM llama3.3:8b`). `PARAMETER` sets generation parameters (temperature, top_p, top_k, etc.). `SYSTEM` defines the system prompt, instructing the model's role and behavior. `TEMPLATE` customizes the prompt template, allowing fixed text to be added before or after input. Example basic Modelfile: `FROM llama3.3:8b PARAMETER temperature 0.3 PARAMETER top_p 0.9 SYSTEM You are a professional technical support agent. Strive for polite and accurate responses.` Save this file as `Modelfile` and run `ollama create tech-support -f Modelfile` to create a new model named `tech-support`. Verify with `ollama list` and start using it immediately with `ollama run tech-support`.
Best Practices for Industry-Specific Persona Configuration
The success of business-specific AI heavily depends on persona configuration in the system prompt. For law firms, instructions like "You are a legal assistant well-versed in Japanese law. Provide general information, not legal advice. Cite relevant statute names in responses" are effective. For medical clinics, clarify constraints: "You are a medical receptionist assistant. Do not provide diagnosis or treatment advice; only offer appointment guidance and general health information." For sales support AI, limit the role: "You are a sales support agent knowledgeable about products. Listen to customer challenges and recommend optimal products. Do not negotiate pricing; refer to sales representatives." B2B companies in Meguro-ku and Setagaya-ku reflect their own sales scripts in system prompts to achieve consistent brand voice.
Output Control Through Parameter Tuning
The `PARAMETER` directive in Modelfile allows fine-grained control over model generation characteristics. `temperature` controls creativity and randomness: closer to 0 produces deterministic, consistent output, while closer to 1 yields diverse, creative output. For customer support, 0.1-0.3 is recommended; for content generation, 0.7-0.9. `top_p` (nucleus sampling) is a cumulative probability threshold, typically 0.9. `top_k` is the upper limit on candidate tokens, with 40-100 being standard. `repeat_penalty` suppresses repetition, with 1.1-1.3 being appropriate. `num_ctx` is the context window size; increase to 4096 or 8192 for long conversation histories. Example: `PARAMETER temperature 0.2 PARAMETER top_p 0.85 PARAMETER repeat_penalty 1.15 PARAMETER num_ctx 8192`. Adjusting these parameters to business requirements achieves optimal response quality.
Input Format Control with TEMPLATE Directive
The TEMPLATE directive defines how user input is passed to the model. Default templates vary by model, but customization can enforce specific input formats. For example, assuming structured inquiry form input: `TEMPLATE """{{ .System }} Inquiry: {{ .Prompt }} Please respond to the above inquiry in the following format: 1. Summary 2. Detailed Explanation 3. Next Steps"""`. Defining templates this way ensures all responses follow a consistent format. You can also properly handle chat history using special tokens. Complex templates are difficult to debug, so start with a simple version, test, and expand incrementally.
Importing External Models in GGUF Format
Ollama can import external models in GGUF (GPT-Generated Unified Format) beyond its standard model library. To use GGUF files downloaded from Hugging Face or CivitAI, specify `FROM /path/to/model.gguf` in the Modelfile. For example, importing a Japanese-specialized fine-tuned model (Swallow, Youri, ELYZA, etc.): `FROM ~/models/japanese-model-q4_K_M.gguf PARAMETER temperature 0.4 SYSTEM You are a native Japanese assistant.` The quantization level of GGUF files (q4_K_M, q5_K_M, q8_0, etc.) affects the trade-off between memory usage and accuracy. On a Mac mini with 32GB memory, q4 quantization of 13B models is practical. Companies in Ota-ku and Shinagawa-ku import industry-specific fine-tuned models to achieve higher accuracy than general-purpose models.
Registering Custom Models in OpenClaw
To use custom models created with Ollama in OpenClaw, edit the agent configuration file `~/.openclaw/openclaw.json`. Add a new agent to the `"agents"` array and specify the custom model name in the `"model"` field. Example: `{"name": "legal-advisor", "model": "ollama:legal-assistant", "endpoint": "http://localhost:11434", "tools": ["search_law_database"]}`. Define multiple custom models and differentiate them by specific channels or keywords in the `"bindings"` section. For example, route technical questions to the `tech-support` model and legal questions to the `legal-assistant` model. OpenClaw automatically selects the appropriate agent based on priority and pattern matching, so users interact seamlessly with the optimal model without awareness.
A/B Testing with Multi-Agent Routing
One powerful feature of OpenClaw is the ability to run multiple agents (models) in parallel for A/B testing. Create different custom models for the same task and compare performance with actual user interactions. For example, prepare two models for customer support (Model A: temperature 0.2, concise answers; Model B: temperature 0.4, detailed explanations) and randomly distribute traffic. Collect metrics such as response time, user satisfaction, and escalation rate from OpenClaw logs and verify statistically significant differences. Deploy the winner across all channels and conduct the next A/B test with further improvements. This continuous experimentation cycle gradually improves model accuracy. Startups in Setagaya-ku and Shibuya-ku maximize AI ROI with such data-driven approaches.
Version Control and Model Iteration
Since Modelfiles are text files, they can be managed with version control systems like Git. Create a `models/` directory in your project repository and place Modelfiles for each business use case (e.g., `models/customer-support-v1.modelfile`, `models/sales-assistant-v2.modelfile`). Record change history in commit messages and track which version demonstrated which performance. When deploying a new version, create it with tags in Ollama: `ollama create customer-support:v2 -f models/customer-support-v2.modelfile`. Update the model name in OpenClaw's configuration to `ollama:customer-support:v2`, and the new version becomes active immediately. If issues arise, you can quickly roll back to the previous version. Review Modelfiles as a team, share improvement ideas for system prompts and parameters, and continuously enhance model quality.
Evaluation and Benchmarking of Business-Specific Models
To objectively evaluate custom model quality, prepare a business-specific test set. Select 50-100 representative questions from actual customer inquiries and have humans create expected answers (gold standard). Run each custom model on the test set and evaluate responses automatically or manually. Evaluation metrics should include accuracy (contains correct information), completeness (all necessary information included), conciseness (not verbose), and tone (matches brand voice). Using the LLM-as-a-Judge method, you can also have GPT-4 or other LLMs evaluate response quality. Visualize benchmark results in spreadsheets or dashboards and compare different Modelfile versions and parameter settings. Companies in Meguro-ku and Shinagawa-ku conduct model evaluations quarterly for continuous improvement.
Cost Reduction and Environmental Considerations
Local AI systems with Ollama and OpenClaw achieve significant cost savings compared to cloud APIs. OpenAI API can cost tens of thousands of yen per month for 100,000 requests, while Ollama only incurs electricity costs. Running a Mac mini (M4 Pro, 20-40W power consumption) 24/7 results in monthly electricity costs of just a few hundred yen. Initial investment (Mac mini itself) can be recovered in a few months. Additionally, eliminating data center communication reduces CO2 emissions. Downsizing custom models (8B or 13B models) further reduces power consumption while maintaining sufficient performance. SMEs in Ota-ku and Shinagawa-ku are shifting to local AI, prioritizing these cost and environmental benefits.
Oflight Inc.'s Custom AI Model Development Services
Oflight Inc. (Shinagawa-ku, Tokyo) supports the development of business-specific AI models using Ollama's Modelfile. We conduct requirements interviews, select optimal base models, design personas, tune parameters, and create templates with end-to-end support. We also handle importing external models in GGUF format and integrating fine-tuned models. Integration with OpenClaw enables multi-channel deployment on LINE, Slack, Discord, and continuous improvement through A/B testing. Serving clients primarily in Shinagawa-ku, Ota-ku, Meguro-ku, and Setagaya-ku, we provide AI solutions specialized for diverse industries including legal, medical, real estate, and manufacturing. If you are interested in building business-optimized AI models, please contact us.
Feel free to contact us
Contact Us