Skip to content

Agents

Conventional wisdom holds that "one agent = one LLM". But in ParaLLeM, an agent is a program. This program probably uses LLMs to automate much of its decision making, but the agent can also ask functions and the user.

An agent is simply 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"))

An agent is more than an LLM

After decoupling the agent concept from one single LLM, it becomes natural to express concepts including:

  1. 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")
    

  2. 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()}.")
    

  3. 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?")
    

See also