Performance: Custom agent logic
Custom agent logic affects how quickly and efficiently the agent processes inputs and generates outputs, impacting interaction responsiveness and overall user experience.
Jump into concepts and practice - no test required
def agent_decision(input): cache = {} def get_result(key): if key not in cache: if key in ['A', 'B']: cache[key] = complex_call_1() elif key == 'C': cache[key] = complex_call_2() else: cache[key] = complex_call_3() return cache[key] return get_result(input)
def agent_decision(input): # Multiple nested if-else checks with redundant calls if input == 'A': result = complex_call_1() elif input == 'B': result = complex_call_1() elif input == 'C': result = complex_call_2() else: result = complex_call_3() return result
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Redundant heavy calls in logic | Minimal | 0 | Low | [X] Bad |
| Cached and simplified logic | Minimal | 0 | Low | [OK] Good |
plan and run for behavior.plan method decides the next action, so overriding it customizes decisions.class MyAgent:
def plan(self, input_text):
if 'hello' in input_text.lower():
return 'Greet'
return 'Ignore'
agent = MyAgent()
print(agent.plan('Hello there!'))class CustomAgent:
def plan(self, input_text):
if input_text.contains('test'):
return 'Found'
return 'Not Found'