Skip to content

data_classes.py - Multiple bugs and missing imports #5

@keadachik

Description

@keadachik

Bugs in data_classes.py - Runtime Errors

Summary

data_classes.py contains multiple bugs that cause runtime errors when executing the project code.


Bug 1: Missing re Module Import

Location: project/data_classes.py in safe_extract_json function

Problem:
The safe_extract_json function uses re.sub() and re.search() but the re module is not imported.

Code:

response_text = re.sub(r'\.\s*\.+', '.', response_text)
match = re.search(pattern, response_text, re.DOTALL)
json_str = re.sub(r'\.\s*$', '', json_str)
json_str = re.sub(r'[^\x20-\x7E\n\r\t]', '', json_str)

Error:

NameError: name 're' is not defined

Fix:

import re

Bug 2: Logic Error in _update_person_state

Location: project/data_classes.py in _update_person_state method

Problem:
The function adds the person's own ID to their meeting history instead of the other person's ID.

Code:

if meeting_success and person.id not in person.meeting_history: 
    person.meeting_history.append(person.id)  # Bug: Should append other_person.id

Expected Behavior:
The meeting history should track who this person has met with, not themselves.

Fix:

def _update_person_state(self, person: Person, other_person: Person, meeting_success: bool, satisfaction: float, time_slot: TimeSlot):
    # ... existing code ...
    if meeting_success and other_person.id not in person.meeting_history: 
        person.meeting_history.append(other_person.id)  # Append other person's ID

Note: This function signature needs to be updated to accept other_person parameter, and all call sites need to be updated accordingly.


Bug 3: Undefined Variables in run_local_agent_evaluation

Location: project/data_classes.py in run_local_agent_evaluation function

Problem:
The run_local_agent_evaluation function references variables that are defined in starter_agentic_traces.py but not imported into data_classes.py.

Code:

for persona_idx, persona in enumerate(system_prompt_configurations):  # undefined
    # ...
    current_agent = NPC(  # NPC not imported
        # ...
        tools=TOOLS,  # undefined
    )
    tool_loop = AgentToolLoop(current_agent, max_iterations=8)  # undefined

Fix:

from npcpy.npc_compiler import NPC
from starter_agentic_traces import system_prompt_configurations, TOOLS, AgentToolLoop

Note: This creates a circular import dependency if starter_agentic_traces.py imports from data_classes.py. Consider refactoring to avoid circular imports, or move shared definitions to a separate module.


Bug 4: Undefined Function npcpy_get_llm_response

Location: project/data_classes.py in PersonDescriptor.generate_description method

Problem:
The function calls npcpy_get_llm_response which does not exist. Should use get_llm_response from npcpy.llm_funcs.

Code:

return npcpy_get_llm_response(prompt, temperature=0.9).get('response')

Error:

NameError: name 'npcpy_get_llm_response' is not defined

Fix:

from npcpy.llm_funcs import get_llm_response

# In generate_description method:
return get_llm_response(prompt, model='qwen3:1.7b', provider='ollama', temperature=0.9).get('response')

Note: The model parameter should also be specified to avoid using the default 'llama3.2' model which may not be available.


Impact

  • safe_extract_json function: Will fail with NameError: name 're' is not defined when called
  • PersonDescriptor.generate_description method: Will fail with NameError: name 'npcpy_get_llm_response' is not defined
  • run_local_agent_evaluation function: Completely non-functional due to undefined variables
  • Meeting history tracking: Incorrectly tracks self-meetings instead of actual meetings with others
  • Runtime errors: Will fail with NameError when these functions are called

Environment

  • Python 3.10
  • Vocareum Lab environment
  • Project: Agentic Reinforcement Learning

Related Files

  • project/data_classes.py - Contains all bugs
  • project/starter_agentic_traces.py - Contains definitions for system_prompt_configurations, TOOLS, AgentToolLoop
  • project/starter_sft.py - May import and use data_classes.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions