Subjective Functions
Subjective Functions
As artificial intelligence continues to evolve, so does its role in programming. One of the exciting concepts emerging is the integration of AI in a way that feels seamless, flexible, and predictable. subjective functions are primarily controlled by AI, but still rely on clear parameters and structure provided by the developer.
Subjective functions allow you to describe complex tasks in natural terms and let the AI handle the logic. They simplify programming by combining the power of AI with the precision and control of traditional coding. Instead of writing out complex, multi-step logic, you define the goal and the AI figures out how to achieve it.
In this blog, we’ll explore what subjective functions are, how they work, and how they can make coding easier by letting AI handle the complexity while you stay in control of the structure.
What Are Subjective Functions?
A subjective function is a function where the developer defines the input, output, and purpose, but leaves the actual implementation to an AI.
The developer focuses on what needs to be done—the AI figures out how to do it.
Objective vs. Subjective Functions
- Objective functions – Traditional functions where the developer writes out the step-by-step logic.
- Subjective functions – Higher-level functions where the developer defines the goal, and the AI handles the logic and execution.
Why Use Subjective Functions?
Subjective functions are especially useful for:
- Complex, multi-step tasks – Like data analysis, summarization, or natural language processing.
- Tasks requiring reasoning or decision-making – Let the AI decide the best approach based on context.
- Dynamic behavior – When the best solution depends on varying input conditions.
When Not to Use Subjective Functions
For simple, straightforward tasks (like file handling, database queries, or math operations), objective functions are usually the better choice. AI introduces more overhead than necessary for basic tasks—so it’s best to keep subjective functions focused on complex logic where AI offers a clear advantage.
How Do Subjective Functions Work?
To get a clearer picture, let’s consider a scenario:
You have an invoice and need to generate a summary. This is not a simple task—there could be multiple fields to evaluate, context to understand, and natural language generation involved. Instead of writing out all that logic yourself, you can define a subjective function to handle it:
- You define the function signature (parameters and return type).
- You provide a description of what the function should accomplish.
- The AI takes care of generating the summary based on those inputs.
The AI handles the complexity—context processing, natural language generation, data extraction—while you simply define the goal and the structure.
Simplified Usage with Annotations
In most cases, using a subjective function is straightforward. You can register one with a simple annotation, and the system will handle most of the configuration with sensible defaults.
Here’s a basic example:
@register_subjective_function
def generate_invoice_summary(invoice_data: dict, max_length: int = 200) -> str:
"""
Generates a summary of the invoice. This function is powered by AI.
"""
# The AI handles the function body based on input and description.
In this example:
- The
@register_subjective_functionannotation tells the system to treat this as a subjective function. - The AI handles the logic of summarizing the invoice.
- Parameters and return types are inferred automatically.
- Defaults like model type, execution timeout, and behavior are handled internally by the system.
What’s Handled Automatically?
- The AI model (e.g., GPT-4) is chosen based on defaults.
- Timeout and execution limits are set to reasonable defaults.
- Basic error handling is built in.
- If the AI fails, you can define a fallback function to handle it (optional).
This simple approach reduces the need for writing boilerplate code and keeps the interface clean and predictable.
Full Registration for More Complex Cases
If you need more control over how the AI handles the function, you can register it manually. Here’s an example of a more detailed setup:
def generate_invoice_summary(invoice_data: dict, max_length: int) -> str:
"""
Generates a summary of the given invoice data.
"""
# Register the function with more control
register_subjective_function(
func=generate_invoice_summary,
model="gpt-4",
parameters=[
{"name": "invoice_data", "type": "dict", "description": "The invoice data to summarize"},
{"name": "max_length", "type": "int", "default": 200, "description": "Maximum length for the summary"}
],
return_type="str",
description="Generates a summary of an invoice.",
fallback="default_invoice_summary", # Fallback function in case of failure
linked_functions=["calculate_tax", "fetch_user_details"], # Functions the AI can call
timeout=5, # Timeout in seconds
)
This approach allows you to:
- Set detailed parameters (like
max_length,invoice_data). - Choose which AI model to use (
gpt-4). - Specify fallback functions and linked functions.
- Adjust execution timeouts and behavior.
This more detailed registration method is useful when you want to tightly control how the AI operates.
The Advantages of Subjective Functions
Subjective functions give you the best of both worlds:
- Reduced complexity – Offload multi-step, dynamic, or complex logic to the AI.
- Cleaner code – The AI handles the "how," so you write less code.
- Flexibility – You can mix and match subjective and objective functions.
- Fallbacks and control – If the AI fails, you can define exactly what should happen next.
- Easier to maintain – Complex logic stays abstracted within the AI, keeping your code more manageable.
By offloading complex logic to subjective functions, you simplify development without sacrificing control.
Conclusion: A Balanced Approach to AI in Programming
Subjective functions are a powerful way to simplify complex coding challenges. They let you define what needs to be done while the AI figures out how to do it.
This creates a natural balance between traditional objective coding (where you define the logic) and AI-powered subjective coding (where you define the goal).
The beauty of subjective functions is that you can use them as needed. For simple tasks, stick with objective functions. For more complex, multi-step logic or reasoning, subjective functions let you reduce complexity without losing control.
By combining AI’s power with structured coding, subjective functions open up new possibilities for how we write software.