Artificial Intelligence in Business Rules
Version 6 introduced a fundamentally new approach to AI integration in business rules engines, and version 7 makes AI a natural part of the whole platform: rule authoring, rule evaluation, rule management, testing, and the investigation of production decisions.
Unlike traditional "AI-enabled" platforms that tie customers to vendor-specific models, APIs, or hosted services, Code Effects uses the models your organization chooses, on the infrastructure your organization controls, while the decisions themselves stay deterministic.
AI support in the Rule Editor and Rule Engine is built around two core features introduced in version 6:
Together, these features allow organizations to combine deterministic business rules with probabilistic AI-driven evaluation while maintaining full control over models, prompts, infrastructure, security, and execution flow.
Version 7 adds AI to rule management with the optional Rule Repository, Audit and MCP server:
- The AI Rule Editor, which writes or changes a rule from instructions in any language
- The AI Assistant, which works across the entire rule database, recorded decisions and activity
- The MCP server, which lets external AI agents work with your rules through the Model Context Protocol
- Structural guardrails and human authority over every critical action, whoever or whatever does the work
Adaptive Source
Context-Aware Rule Authoring
Historically, Code Effects supported several source models for rule authoring and evaluation:
These models remain fully supported in version 7. However, they all share one characteristic: the editor receives a predefined static data surface.
Adaptive Source introduces a completely different approach.
Instead of exposing a fixed set of fields, methods, and actions to the rule editor, Adaptive Source allows the available rule elements to be generated dynamically and contextually during rule authoring. The editor requests menu items on demand as the user builds or updates a rule. Your application decides what should appear next. In version 7, Adaptive Sources are more complete: the unified source provider supplies source identity as well as inline and reusable rules to the editor, and the Rule Repository works with Adaptive Sources the same way it works with .NET types and Source XML.
At every stage of rule creation, the editor sends the current rule context to your code. Your implementation can then dynamically determine:
- Which fields should be available
- Which operators should be displayed
- Which methods are contextually relevant
- Which actions can be executed
- Which UI paths should be hidden entirely
This logic can be driven by:
- AI models
- Internal business logic
- Metadata systems
- Configuration files
- External services
- Any combination of the above
The editor itself remains completely independent of the decision mechanism. Code Effects does not require or enforce any specific AI provider, prompt structure, inference engine, or orchestration layer.
Example: Contextual Product Rules
Imagine an e-commerce platform that sells both TVs and shoes.
A rule author begins building a rule:
If Product Type is TV and ...
At this point, the next menu should display only TV-related fields:
- Screen Size
- Voltage
- Display Technology
- Wall Mount Type
Fields related to shoes are no longer contextually relevant. When the editor requests the next menu, your application receives the current rule context:
- Field:
ProductType
- Operator:
=
- Value:
TV
Your logic can then dynamically generate the next valid rule surface. The editor provides the complete current rule context, not just the most recently added condition.
If the user later changes the product type from TV to Shoes, the entire downstream rule context may become invalid. Adaptive Source addresses this using Context Resetters.
// Example of JSON definition
{
"Value": "Inventory.Type",
"DisplayName": "Product Type",
"Description": "Test description",
"DataType": 6, // Enum
"ResetsContext": true,
"Settings":
{
"EnumName": "ProductType",
"TypeName": "TestProject.Rules.ProductType"
}
}
When a context-resetting condition changes, the editor automatically removes all dependent rule elements that no longer make semantic sense. The user can either continue editing or restore the previous state using Undo.
Your Models, Your Intelligence Layer
Adaptive Source defines how AI can guide rule authoring in Code Effects. Instead of embedding a particular AI model directly into the engine itself, Code Effects exposes the rule-authoring pipeline in a way that allows organizations to integrate:
- OpenAI
- Anthropic
- Gemini
- Azure AI
- Local LLMs
- On-prem inference servers
- Proprietary internal models
or no AI at all.
The platform provides the orchestration layer. You control the intelligence layer.
Prompt-Enabled Rule Elements
Integrating AI Into Rule Evaluation
The second major AI feature introduced in version 6 is the Prompt flag. The Prompt flag can be applied to any string field, method parameter, or method return value:
// Reflection source example
// In-rule method with prompted string parameter
[Method(DisplayName = "Get AI Probability Score")]
public decimal GetScore (
[Parameter(Prompt = true)] string prompt)
{
// Your AI implementation
return GetTheScore(prompt);
}
// In-rule method with prompted return
[Method(DisplayName = "Load Definition")]
[return: Return(Prompt = true)]
public string GetDefinition ( )
{
return GetYourDefinition();
}
// Prompted field
[Field(Prompt = true)]
public string Prompt { get; set; }
When enabled, the editor displays a dedicated Prompt dialog for long-form structured input whenever the user interacts with a prompted field, return value, or method parameter. Although this feature can be used for any extended text input, its primary purpose is AI-driven rule evaluation.
AI as Part of Deterministic Rules
Consider the following in-rule method:
[Method(DisplayName = "Ask AI")]
public bool AskAI(
[Parameter(Prompt = true)] string prompt)
{
return GetYourAiResult();
}
A rule author can then create logic such as:
If Ask AI ( "Determine whether this claim appears fraudulent" )
is True
then Escalate Claim
else Auto Approve
where EscalateClaim() and AutoApprove() are examples of C# public methods used here as rule actions. The rule itself remains deterministic. The AI-powered evaluation becomes just another executable condition inside the decision flow.
This architecture allows organizations to combine:
- deterministic business logic
- AI inference
- compliance constraints
- explainability
- workflow automation
inside a single executable decision system. With Audit, an evaluation of such a rule is recorded like any other, including the branch it took, so the role the AI condition played in a particular decision can be reviewed later.
Deterministic Decision Automation with AI Inside
Code Effects does not attempt to become an AI platform. Instead, it provides the infrastructure necessary to bring the AI models your organization chooses into enterprise decision automation while preserving:
- your choice of models and providers
- infrastructure ownership
- prompt ownership
- security boundaries
- deployment flexibility
- deterministic execution control
This allows organizations to evolve their AI strategy independently of the business rules engine itself. As models, providers, and deployment requirements change, the decision infrastructure remains the same.
AI in Rule Management
Version 7 brings AI into the place where rules are written, tested, approved and investigated. When your application registers one or more models, the Rule Repository adds an AI Rule Editor and an AI Assistant. Any LLM with tool calling can be used through IChatClient; Anthropic's Claude and OpenAI's GPT models have been tested. Your application chooses the models and supplies the API keys, and the AI features work under each user's permissions. Both are part of the Rule Repository library and do not require the MCP server. See AI setup.
AI Rule Editor: Describe the Logic in Any Language
The AI Rule Editor sits right next to the standard Rule Editor. Users describe the logic they need, or a change to an existing rule, in any language, and AI composes the rule from their instructions. Every generated rule is checked against its source object, with validation results shown immediately, and users can move between conversational authoring and direct editing while keeping the latest rule.
AI Assistant: Work Across the Rule Database
The AI Assistant gives users a dedicated conversation for working across the entire rules database. It can find and explain rules, create and update rules, rule versions, drafts and tests, and run tests. It can also query rules, test history, recorded evaluations and user activity, calculate aggregates and support reporting, so users can ask business questions such as:
- "Why was loan application LN-2048 declined, and which conditions determined the result?"
- "How many loan applications for amounts over $100,000 were evaluated last quarter, and how many were declined?"
- "Which versions of our lending rules were tested before they went live?"
- "Who changed this rule, when did it change, and what happened in subsequent evaluations?"
Authorized users can also upload PDF policy documents and compare their contents with existing rules, recorded evaluations, activity and aggregate results, for example to find where the eligibility criteria in a policy document differ from the current lending rules. The Assistant shows its steps as it works, preserves conversation history, and reports token usage and cost for each conversation. Users with the appropriate permissions can review other users' AI sessions.
The MCP Server: Rules for External AI Agents
The MCP server lets the AI clients your people already use work with your rules through the Model Context Protocol. Agents can inspect sources, rules, tests and recorded evaluations, find, explain, write and test rules, and use the available history to investigate decisions and support reporting. They sign in through your application's own OAuth authentication and work within the same permissions as the person they represent. The MCP server runs in your own ASP.NET Core application and works with the Rule Repository, Audit, or both. See What Agents Can Do.
Structural Guardrails for AI-Generated Logic
Whoever writes a rule, a person or an AI agent, every saved rule is structurally valid against its source object. As AI creates rule versions, drafts and tests, the platform checks the rule content against its structure and source, rejects structurally invalid logic and returns validation feedback the AI can act on. Because Rule XML is a precise, documented format rather than free text or generated code, agents can verify these properties without someone manually reading every result, and a rule written by AI is shown in its entirety in the same readable form as any other rule.
Structural validity establishes that a rule is well formed and compatible with its source. Whether it expresses the intended business policy is what tests, review and approvals are for: AI generation alone cannot guarantee business correctness.
Human Authority over Critical Actions
AI agents acting on behalf of users, agents acting independently, and services your application has not identified as users can never delete, approve, put a rule into production or take it offline, even if the host application grants those permissions by mistake. Every rule version an AI saves requests a person's approval, and tests that would call production code require confirmation from the person using the agent. Activity records identify what an AI agent did and the person it represented, and Reviewing Agent Work shows how people check it.
AI may propose and prepare. Authorized people remain responsible for the business logic that reaches production.
Explaining Production Decisions with AI
With Audit, production evaluations are recorded: when each decision ran and for whom, the exact rule and source versions, the values read, the branch taken and the actions that followed. Users can review and replay any recorded decision step by step, and the AI Assistant and MCP agents can investigate the same records to explain why a result occurred or to report on many decisions at once. Any recorded decision can become a test using its actual production data.
A Rule Language and Sources Built for AI
Version 7 expands the rule language with membership lists (is in, is not in), inclusive ranges, collection functions such as exists, all, first, last and count with, string concatenation, date shifts, durations, and inline rules. These give AI clearer building blocks for understanding and generating logic, so a decision stays one complete, readable rule rather than a collection of fragments. Sources can also carry member-level aliases and descriptions that give AI agents business context without changing the labels users see, and a correlation field, such as a loan number, that ties recorded decisions to a particular business case.
Where AI Fits in the Decision
AI is very good at interpreting documents, requests and unstructured data. Business policy needs the opposite: explicit conditions, repeatable results, version history, approval and explainability. Code Effects puts each where it belongs:
AI interprets. Code Effects decides. The workflow acts.
The Rule Engine and the Rule Editor, including Adaptive Source and prompted rule elements, are free for personal, community, development and research use. The Rule Repository, Audit and the MCP server are licensed separately; see Code Effects Packages.