EMR-AGENT is an agent-based framework for extracting structured clinical data from electronic medical records (EMRs). It automates cohort selection, feature extraction, and code mapping by replacing manual rule writing with dynamic, language-model-based interactions. EMR-AGENT queries the database to infer schemas and documents, and uses SQL not only for data retrieval but also for database observation and decision-making. Performance and generalization capabilities are demonstrated through benchmarking results against three EMR databases: MIMIC-III, eICU, and SICdb. The code is publicly released.