Skip to content

Agent

What is an Agent?

After using bots, maps and workflows, you decide that you want something that can use all of them together and will use them each at the right time. That is where Agents come in to give you an easy way to combine everything together (including other agents) in a simple-to-use package.

Create a Basic Agent

To create an agent using the Agent class from the dandy module similar to how we created the other Dandy processors (bot, decoder and workflow).

from dandy import Agent, Bot, BaseIntel


class IdeaBot(Bot):
    llm_role = 'Creative Idea Maker'

    def process(self, user_input: str) -> BaseIntel:
        return self.llm.prompt_to_intel(
            prompt=user_input
        )


class AssistantAgent(Agent):
    # This attribute is required and determines which other processors you want this agent to have access to using.
    processors = (
        IdeaBot,
    )


intel = AssistantAgent().process('Can you give me an idea for a drawing?')

print(intel.text)
Imagine a surreal library where books float in mid-air, each one glowing with a different emotion—joy, sorrow, curiosity, fear—visible as swirling colors. The shelves are made of intertwined roots and vines, growing from the floor to the ceiling, forming a living labyrinth. In the center, a single, ancient book lies open, its pages blank, but as you look closer, tiny creatures made of ink and light crawl across the pages, writing stories in real time. A curious child, drawn by the glow, reaches out to touch it, and the moment their fingers make contact, the entire library begins to whisper in a thousand voices, each voice a different story waiting to be told.

Note

The above example only contains one processor so it will be assigned to process everything that the agent does. You can assign anything that is a sub class of the BaseProcessor which is everything in Dandy with a process method.

Example Implementation

Below is a quick demonstration on how you would build out an agent that would help you write emails to any of your favorite museums!

Set up the Required BaseIntel Objects.

intelligence/intel.py

Create a mock bot to help us find the museum's email address and one that recursively edits the email to make it more informative and creative.

intelligence/bots.py

Use a decoder to pull out the intent from the user request to discover a subject to talk about.

intelligence/decoders.py

Put it all together in an Agent.

intelligence/agents.py

We can now import the agent and use it to process an email.

museum.py
from intelligence.agents import MuseumEmailLlmAgent

email_intel = MuseumEmailLlmAgent().process(
    f'The Royal Tyrell Palaeontology Museum, green colors are awesome and my email is [email protected]'
)

print(email_intel)

The Agent will build a plan, user the appropriate processors and return the result as a EmailIntel object.

Ouput
{
    "to_email_address": "[email protected]",
    "from_email_address": "[email protected]",
    "subject": "Inquiry About Paleontology Exhibits and Green Colors",
    "body": "Dear Sir/Madam,\n\nI hope this message finds you well. My name is A. Person, and I am a passionate enthusiast of paleontology, particularly fascinated by the vibrant green hues found in fossilized remains. Your esteemed museum, The Royal Tyrell Palaeontology Museum, has always been a source of inspiration for my studies and curiosity.\n\nI would be immensely grateful if you could provide me with information on any upcoming exhibitions or events that focus on paleontology and the presence of green colors within fossils. Additionally, I am interested in learning more about your museum's research initiatives related to this topic.\n\nThank you very much for considering my request. I look forward to hearing from you soon.\n\nBest regards,\nA. Person"
}