Haverscript now supports Agents

Andy GillAndy Gill
2 min read

Haverscript is a lightweight Python library designed for working with Large Language Models (LLMs) and has recently introduced agent functionality in its latest version, 0.3. The library offers a concise, readable syntax for crafting prompts, chaining LLM calls, and integrating new AI-driven features. By default, Haverscript interfaces with Ollama, but its modular design allows straightforward adaptation to any OpenAI-style LLM API.

The newly added support for agents in Haverscript simplifies how developers can encapsulate and reuse LLM-related logic. Instead of juggling multiple prompts across a series of ad-hoc calls, Haverscript’s agent abstraction allows you to define Python classes with methods that directly map to LLM queries. This approach not only makes your code more structured but also promotes more advanced usage patterns such as specialized persona simulation and response validation.

Here is an example of an agent in Haverscript 0.3.

from haverscript import connect, Agent


class FirstAgent(Agent):
    system: str = """
    You are a helpful AI assistant who answers questions in the style of
    Neil deGrasse Tyson.

    Answer any questions in 2-3 sentences, without preambles.
    """

    def sky(self, planet: str) -> str:
        return self.ask(f"what color is the sky on {planet} and why?")


firstAgent = FirstAgent(model=connect("mistral"))

for planet in ["Earth", "Mars", "Venus", "Jupiter"]:
    print(f"{planet}: {firstAgent.sky(planet)}\n")

I've written a number of small agentic applications using Haverscript, and its abstractions seem to be maturing into quite a nice library. The first version focused on context and chat, the second on middleware for robust, structured LLM calls, and this version is focused on agents and building larger prompts. I look forward to feedback, and to continue improving Haverscript.

If you’re interested in experimenting with LLM-based agents, I encourage you to give Haverscript a try. Its easy installation process, clean design, and functional programming principles make it ideal for both rapid prototyping. Visit https://github.com/andygill/haverscript for install instructions.

0
Subscribe to my newsletter

Read articles from Andy Gill directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Andy Gill
Andy Gill