Exploring the Intersection of LLMs and Humanities
Humanities research means wrestling with long, dense primary sources. I built a small CLI agent that ingests a text and returns structured analysis: core thesis, key figures, historical context, and suggested connections
Humanities research means wrestling with long, dense primary sources. I built a small CLI agent that ingests a text and returns structured analysis: core thesis, key figures, historical context, and suggested connections. Because it runs on Oxlo.ai, the same flat per-request price applies whether I pass a paragraph or a full chapter, so I never have to trim a source to save on token costs. See https://oxlo.ai/pricing for details.
What you'll need
- Python 3.10 or newer
- The OpenAI SDK installed with
pip install openai - An Oxlo.ai API key from https://portal.oxlo.ai
- A plain-text primary source to analyze (I use a public domain excerpt from Machiavelli)
Step 1: Lock down the system prompt
I need the model to return predictable JSON and avoid hallucinating dates. The system prompt enforces a strict schema and requires the model to flag anything uncertain.
SYSTEM_PROMPT = """You are a humanities research assistant. Analyze the provided primary source text and return a JSON object with exactly these keys:
- thesis: a one-sentence summary of the core argument.
- entities: a list of important people, places, or concepts with a one-sentence description for each.
- context: a short paragraph situating the text in its historical period.
- connections: a list of related texts or movements the reader should explore next.
- uncertainty: a list of any claims you are not certain about, or an empty list if none.
Be concise. Do not invent specific page numbers or dates you do not see in the text."""
Step 2: Initialize the Oxlo.ai client
Oxlo.ai exposes a fully OpenAI-compatible endpoint, so the standard SDK drops in without changes. There are no cold starts on popular models, which keeps the CLI responsive.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
Step 3: Build the analyzer function
I wrap the API call in a small function. I use kimi-k2.6 because its 131K context window handles long essays, and Oxlo.ai's flat per-request pricing means I do not have to worry about token costs ballooning when I pass in a lengthy chapter.
import json
def analyze_text(source: str) -> dict:
response = client.chat.completions.create(
model="kimi-k2.6",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": source},
],
response_format={"type": "json_object"},
)
return json.loads(response.choices[0].message.content)
Step 4: Add a CLI entrypoint
I add a small argument parser so the script accepts any text file. This makes it reusable across a whole corpus.
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Analyze a primary source.")
parser.add_argument("file", help="Path to a plain-text file")
args = parser.parse_args()
with open(args.file, "r", encoding="utf-8") as f:
source = f.read()
result = analyze_text(source)
print(json.dumps(result, indent=2))
Run it
Save the full script as humanities_agent.py, create a file named prince_excerpt.txt with the passage below, and run the agent.
python humanities_agent.py prince_excerpt.txt
Sample input text:
When evening comes, I return home and go into my study. On the threshold I strip off my muddy, sweaty, workday clothes, and put on the robes of court and palace, and in this graver dress I enter the antique courts of the ancients and am welcomed by them, and there I taste the food that alone is mine, and for which I was born. And there I make bold to speak to them and ask the motives of their actions, and they, in their humanity, reply to me. And for the space of four hours I forget the world, remember no vexation, fear poverty no more, tremble no more at death: I pass indeed into their world.
Example output:
{
"thesis": "The author finds spiritual refuge and intellectual nourishment in the study of classical antiquity, which allows him to transcend worldly anxieties.",
"entities": [
{"name": "the ancients", "description": "Classical authors and thinkers from antiquity whom the narrator consults in his study."}
],
"context": "This passage reflects Renaissance humanist ideals, where the revival of classical learning was seen as a noble pursuit that elevated the mind above political and material concerns.",
"connections": [
"Petrarch's letters on the contemplative life",
"Cicero's De Officiis",
"Renaissance humanism"
],
"uncertainty": []
}
Next steps
Try feeding the agent a much longer text, such as an entire chapter. Because Oxlo.ai charges per request rather than per token, you can use kimi-k2.6's 131K context window to analyze book-length passages without the cost scaling with input size.
Another concrete extension is to batch-process a directory of files and write the structured results into a SQLite database. That gives you a searchable, personal research index built entirely on flat-rate API calls.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.