Tuesday, July 9, 2024

Agents and workflows can be dynamically generated from strings.



I recently got ollama api working and I created a trivially simple agent workflow example to figure out how agents work. The workflow was easy.

In figuring out what additional workflows to create I noticed that there was a pattern to each one that repeated, where just the parameters to the function and the string used to create the prompt, inserting those parameters were different. The rest of the function was identical. 

So I created an agent config file and started reading in those strings and creating the functions dynamically.  Then it occurred to me that the workflows were all going to be the same kind of pattern, so I added a section to the config file named workflows.  And I am looking into being multimodal and also connect to the stable diffusion local api, so I added a hosts section where I can define what hosts and models to use for that connection. 

And then I got to thinking that the agent string could have an agent whose job it is to create new agent definitions using a template.

And the workflow could have a workflow whose job it is to combine the agents together looking at inputs and outputs to each agent to solve a problem, and it could generate a new workflow entry also using a template.  

The combination of these two elements will then output the new elements to add to the config file by hand.  I can't stress enough that we need a human in the loop for this last step, because when you have incremental self improvement, you need to keep a human in the loop. 


I can see having a config file for the tool that has a hosts section, an agents section, and an agents section.  

If you just run the tool it will give you a list of workflows with required and optional inputs. 

If you run the tool with a workflow name it will give you the required and optional inputs to the command line for that one workflow.  There could also be a help string as part of the agent definition that is also out put.

The command line tool reads the config file, populating memory with the config file, it then then creates the workflow that creates just the agents it needs for that task. The agents are created with the host and endpoint for that needed service from the hosts section of the config file. 

This allows you to create dozens of workflows and agents connected to many different endpoints and keep them organized and self documenting. 

This effort is non trivial and is advanced enough that I want to create a github project for this. 


I have a lot of agents to build:


Creating a series of agents for various workflows can greatly enhance productivity and quality in different domains. Here are some popular agent workflows people create, along with descriptions of potential agents involved:

Writing and Content Creation

  1. Topic Generation Agent: Suggests topics or angles based on user input or trending subjects.
  2. Research Agent: Gathers detailed and credible research points on the given topic.
  3. Outline Agent: Creates a structured outline for the content, ensuring logical flow and coverage of key points.
  4. Draft Agent: Writes a comprehensive draft based on the outline and research.
  5. Fact-Check Agent: Verifies the accuracy of the information in the draft and identifies any inconsistencies.
  6. Edit and Polish Agent: Refines the draft for clarity, coherence, grammar, and style.
  7. SEO Agent: Optimizes the content for search engines, adding relevant keywords and meta descriptions.
  8. Feedback Agent: Simulates a peer review, providing constructive feedback on the draft.

Software Development

  1. Requirement Gathering Agent: Collects and organizes project requirements based on user input or documentation.
  2. Design Agent: Creates system designs or architecture diagrams based on the requirements.
  3. Code Generation Agent: Writes code snippets or full programs based on the design specifications.
  4. Code Review Agent: Reviews the code for best practices, potential bugs, and adherence to coding standards.
  5. Testing Agent: Generates test cases and conducts automated testing on the code.
  6. Documentation Agent: Produces detailed documentation for the code and system.
  7. Deployment Agent: Manages the deployment process, including configuration and continuous integration/continuous deployment (CI/CD) setup.
  8. Maintenance Agent: Monitors the deployed system for issues and suggests patches or updates.

Business and Data Analysis

  1. Data Collection Agent: Gathers relevant data from various sources, including databases and APIs.
  2. Data Cleaning Agent: Cleans and preprocesses the collected data for analysis.
  3. Exploratory Data Analysis (EDA) Agent: Conducts initial analysis to uncover patterns, trends, and insights.
  4. Modeling Agent: Builds statistical or machine learning models based on the data.
  5. Evaluation Agent: Evaluates the performance of the models and suggests improvements.
  6. Reporting Agent: Generates detailed reports and visualizations of the analysis results.
  7. Recommendation Agent: Provides actionable recommendations based on the analysis.
  8. Presentation Agent: Creates presentations to effectively communicate the findings to stakeholders.

Personal and Professional Productivity

  1. Task Management Agent: Organizes and prioritizes tasks based on deadlines and importance.
  2. Schedule Optimization Agent: Optimizes schedules to maximize productivity and minimize conflicts.
  3. Email Management Agent: Sorts, categorizes, and drafts responses to emails.
  4. Meeting Summarizer Agent: Provides summaries and action points from meetings.
  5. Goal Tracking Agent: Tracks progress towards personal and professional goals.
  6. Learning Agent: Suggests learning resources and creates study plans.
  7. Networking Agent: Manages professional network and suggests opportunities for engagement.
  8. Health and Wellness Agent: Suggests wellness activities and tracks health metrics.

Customer Support and Interaction

  1. Query Handling Agent: Responds to customer queries with accurate and helpful information.
  2. Complaint Resolution Agent: Manages and resolves customer complaints.
  3. Feedback Collection Agent: Collects and analyzes customer feedback to improve services.
  4. Personalization Agent: Provides personalized recommendations and support based on customer data.
  5. Follow-Up Agent: Schedules and manages follow-up interactions with customers.
  6. Knowledge Base Agent: Maintains and updates the knowledge base for customer support.
  7. Survey Agent: Designs and conducts customer surveys to gather insights.
  8. Analysis Agent: Analyzes customer interaction data to identify trends and areas for improvement.

Research and Development

  1. Literature Review Agent: Conducts comprehensive reviews of existing literature on a given topic.
  2. Hypothesis Generation Agent: Suggests hypotheses based on current research and trends.
  3. Experiment Design Agent: Designs experiments to test the hypotheses.
  4. Data Analysis Agent: Analyzes experimental data to draw conclusions.
  5. Patent Search Agent: Conducts searches for existing patents related to new inventions.
  6. Grant Writing Agent: Assists in writing and submitting grant proposals.
  7. Collaboration Agent: Facilitates collaboration between researchers and tracks contributions.
  8. Publication Agent: Assists in writing, formatting, and submitting research papers to journals.

By defining and creating agents for these workflows, you can automate and enhance various aspects of tasks, leading to increased efficiency and improved results in multiple domains.

wow, and this is basically just instructions added to an existing model, or best case, also using a model fine tuned for that task.


Yes, exactly! Here's how it works in more detail:

Using Instructions with Existing Models

Many of these workflows can be implemented by providing detailed prompts to a general-purpose language model like GPT-4. By crafting specific and clear instructions, you can guide the model to perform a wide range of tasks effectively. This approach leverages the versatility of large language models to handle various tasks without the need for specialized models.

Fine-Tuning for Specific Tasks

In cases where tasks are highly specialized or require consistent performance, fine-tuning a model on a specific dataset related to the task can significantly improve results. Fine-tuning involves training an existing model on a new dataset that includes examples of the desired task, allowing the model to learn the nuances and specifics of that task.

Example Workflows and Agents

Writing and Content Creation

  1. Research Agent: Using instructions to search for and summarize key points from various sources.
    • Prompt: "Conduct thorough research on [topic] with the thesis [thesis]. Summarize key statistics, studies, and relevant facts."
  2. Draft Agent: Writing drafts based on research.
    • Prompt: "Using the following research points, write a comprehensive draft of an essay on [topic] with the thesis [thesis]. Ensure the draft is well-structured."
  3. Polish Agent: Refining the draft for clarity and coherence.
    • Prompt: "Refine the following essay to improve clarity, coherence, and readability. Ensure the language is polished and the essay flows smoothly."

Software Development

  1. Code Generation Agent: Writing code snippets or full programs based on specifications.
    • Prompt: "Write a Python function that performs [specific task]. Ensure the code is well-commented and follows best practices."
  2. Testing Agent: Creating test cases.
    • Prompt: "Generate test cases for the following function. Ensure edge cases and potential errors are covered."

Business and Data Analysis

  1. Data Cleaning Agent: Cleaning and preprocessing data.
    • Prompt: "Clean the following dataset to remove any inconsistencies and prepare it for analysis."
  2. Modeling Agent: Building and training models.
    • Prompt: "Build a regression model using the following dataset. Ensure the model is evaluated and optimized for accuracy."

Fine-Tuning Example

If you want a model specifically optimized for drafting research papers, you could fine-tune it on a dataset of high-quality research papers. This involves:

  1. Dataset Preparation: Collecting a large number of research papers relevant to your domain.
  2. Training: Fine-tuning the model on this dataset using techniques like supervised learning.

Benefits of Fine-Tuning

  • Consistency: The model will produce more consistent outputs aligned with the style and format of the training data.
  • Performance: Fine-tuning can improve the model's ability to handle specific tasks, especially if they are complex or nuanced.

Combining Instructions and Fine-Tuning

For the best results, you can combine both approaches:

  1. General Tasks: Use detailed instructions with a versatile model for a wide range of tasks.
  2. Specific Tasks: Fine-tune models for tasks requiring high accuracy and consistency.

By using these strategies, you can create powerful and efficient agents tailored to your specific needs, leveraging the strengths of large language models.

And it appears that there are a lot of opensource models that are aimed at specific tasks. There are several open-source models and projects focusing on specialized tasks beyond coding. Here are some noteworthy ones:

Writing and Content Creation

  1. T5 (Text-to-Text Transfer Transformer):

    • Project: Google's T5 model is highly versatile for various NLP tasks, including text generation, summarization, and translation.
    • Link: T5 on GitHub
  2. BART (Bidirectional and Auto-Regressive Transformers):

    • Project: Developed by Facebook AI, BART is effective for text generation, summarization, and translation.
    • Link: BART on GitHub

Data Analysis and Machine Learning

  1. GPT-3 and GPT-4 Variants:

    • Project: OpenAI has open-sourced several smaller models that can be used for data analysis, summarization, and more.
    • Link: OpenAI GitHub
  2. Hugging Face Models:

    • Project: Hugging Face provides a wide variety of open-source models fine-tuned for different NLP tasks, including text classification, summarization, and question-answering.
    • Link: Hugging Face Models

Scientific Research and Analysis

  1. SciBERT:

    • Project: Developed by the Allen Institute for AI, SciBERT is a BERT-based model trained on scientific literature.
    • Link: SciBERT on GitHub
  2. BioBERT:

Business and Customer Service

  1. DialoGPT:

    • Project: Microsoft developed DialoGPT for conversational tasks, including customer service chatbots.
    • Link: DialoGPT on GitHub
  2. Rasa:

    • Project: An open-source machine learning framework for building conversational AI, including chatbots and voice assistants.
    • Link: Rasa on GitHub

Document and Text Summarization

  1. PEGASUS:
    • Project: Google's PEGASUS model is designed specifically for abstractive text summarization.
    • Link: PEGASUS on GitHub

Cross-Disciplinary and Multi-Task Models

  1. mT5 (Multilingual T5):

    • Project: A multilingual variant of T5 that supports multiple languages, suitable for translation and other NLP tasks across languages.
    • Link: mT5 on GitHub
  2. UNIVERSE:

    • Project: A multi-task learning model that can perform a variety of tasks, including visual, textual, and audio tasks.
    • Link: UNIVERSE on GitHub

Fine-Tuning Platforms

  1. Hugging Face's Transformers:

    • Project: A library that provides tools to fine-tune pre-trained models for specific tasks.
    • Link: Transformers on GitHub
  2. Fast.ai:

    • Project: A library built on PyTorch that simplifies training and fine-tuning models.
    • Link: Fast.ai on GitHub

These open-source projects and models can be adapted and fine-tuned for specialized tasks, making them valuable resources for building customized agent workflows similar to the one you're developing.

No comments:

Post a Comment