Agents¶
Conventional wisdom holds that "one agent = one LLM". But we believe that an agent is a program. This program happens to use LLMs to automate much of its decision making, but the program can also ask functions and the user.
As a result, agents in ParaLLeM are more powerful.
An agent is just a python function¶
The most idiomatic way to declare an agent is with a vanilla Python function that takes a pllm.AgentContext. For example:
import parallem as pllm
def syllable_count_agent(agt: pllm.AgentContext, word: str) -> str:
ct = agt.ask_llm(f'How many syllables are in "{word}"?')
return ct.final_answer
with pllm.resume_directory(".pllm/example", llm="gpt-5-nano", strategy="sync", load_dotenv=True) as orch:
with orch.agent() as agt:
print(syllable_count_agent(agt, "Hello"))
It is just a python function, nothing special!
An agent is more than an LLM¶
After decoupling the agent concept from one single LLM, it becomes natural to express concepts including:
-
One agent calling multiple LLMs (dynamic model switching):
def polyglot_agent(agt: pllm.AgentContext): resp = agt.ask_llm("What is your model name?", llm="gpt-5-nano") resp2 = agt.ask_llm("What is your model name?", llm="gemini-2.5-flash") -
Non-linear, branching conversations
def animal_agent(agt: pllm.AgentContext): resp = agt.ask_llm("Please simply name 8 animals in a comma-separated list.") for animal in resp.split(","): resp2 = agt.ask_llm(f"Please write a paragraph on the {animal.final_answer.strip()}.") -
Asking non-LLMs
def best_animal_agent(agt: pllm.AgentContext): resp = agt.ask_llm("What is the best animal?") resp2 = agt.ask_human(f"Would you agree that {resp.final_answer} is the best animal?")