0
0
Agentic AIml~20 mins

Intermediate result handling in Agentic AI - ML Experiment: Train & Evaluate

Choose your learning style9 modes available
Experiment - Intermediate result handling
Problem:You are building an AI agent that processes data in multiple steps. Currently, the agent only returns the final output, making it hard to debug or improve intermediate steps.
Current Metrics:Final output accuracy: 78%, no visibility into intermediate step performance.
Issue:Lack of intermediate result handling causes difficulty in understanding where errors occur and slows down improvements.
Your Task
Modify the AI agent to capture and return intermediate results along with the final output, enabling better debugging and performance tracking.
Do not change the core model architecture.
Ensure the agent still returns the final output as before.
Keep the code efficient and readable.
Hint 1
Hint 2
Hint 3
Solution
Agentic AI
class Agent:
    def __init__(self):
        pass

    def process(self, data):
        intermediates = {}
        # Step 1: Normalize data
        max_val = max(data) if data else 1
        step1 = [x / max_val for x in data]
        intermediates['normalized'] = step1

        # Step 2: Square each value
        step2 = [x ** 2 for x in step1]
        intermediates['squared'] = step2

        # Step 3: Sum all values
        final_output = sum(step2)

        return {'intermediate_results': intermediates, 'final_output': final_output}

# Example usage
agent = Agent()
data = [2, 4, 6]
result = agent.process(data)
print(result)
Added a dictionary to store intermediate results during processing.
Returned a dictionary containing both intermediate results and the final output.
Kept the original processing steps unchanged.
Added a check to avoid division by zero when normalizing data.
Results Interpretation

Before: Only final output with 78% accuracy, no insight into intermediate steps.

After: Final output still 78% accurate, plus detailed intermediate results for each processing step.

Capturing intermediate results helps understand and debug complex AI processes without changing model performance.
Bonus Experiment
Extend the agent to log intermediate results to a file for later analysis.
💡 Hint
Use Python's built-in logging module or write intermediate results to a JSON file after each process call.