Build an LLM-driven text-game agent
Company: Cohere
Role: Machine Learning Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
You are given a terminal-based text game and a several-hundred-line Python baseline that uses hand-written heuristic rules to choose actions. Replace the heuristic agent with an agent that queries an LLM to decide the next action.
Describe how you would implement this in Python so that the system is robust and debuggable. Your answer should cover:
- the interface between the game engine and the LLM agent
- how game state should be summarized and serialized into prompts
- how to constrain valid actions and parse model outputs safely
- retries, fallbacks, and context-window management
- logging, tracing, and experiment tracking
- how you would test the agent over repeated runs
- how you would debug failures such as invalid actions, infinite loops, or hallucinated state
Quick Answer: This question evaluates a candidate's understanding of integrating large language models into interactive agents, including prompt design, game-state summarization and serialization, constrained action parsing, retry and fallback strategies, context-window management, logging and experiment tracing, testing, and debugging of failure modes.