Thursday, July 11, 2024

My dynamic workflows agents python script is getting good.

 I got ollama working less than a week ago and I finally was able to build a simple script that automated the steps I have been doing for a while now, by prompting to put chat models into roles and taking that output and prompting with it again. 


The simple script led to  me trying to extend it and seeing patterns in what I was doing.  I noticed that the agent was basically just a text string that got keys replaced.  I was creating  dynamic functions at first from a config file.  I realized that I could replace what the functions were doing with a simple function that just directly did what the function had been doing.


And there is now just one function doing requests to an api, instead of doing the same calls in dozens of functions.  This makes maintaining the code and extending it trivially easy.

The last day I have been reorganizing and extending the config file and making the command line script more use friendly and give better feedback on how to run it. 

The config.json file has aliases, hosts, services, agents, and workflow sections. 

The agents are basically just strings with 0 to three inputs, and have a description and a string with embedded tokens. Probably if you are giving more than 3 inputs you need to divide the agent up into two or more agents. 



Basically it is just a string that has specific parts replace to better handle a chat query to perform a task. The other stuff in the agent entry are just meta data about how to handle the agent. 

I can call an agent as a singleton workflow that gets created from the singleton entry in the workflow section of the config.json file. Like this:

$ python3 ./dynamic_workflows_agents.py idiomatic_remover --input_text "it is raining cats and dogs" 


It is heavily raining.

or I can build a bigger workflow from a series of agents that take results from one agent and pass them to the next agent.  


You can see that the params are mapped from one agent to the next in the 

     "research": "$research_result

line, the $CLI variables are filled in from the command line.  This carries the output from the previous agent to the input of the next agent.

The host and model entries have been updated now with an alias.  Default is just one alias.  By having defaults and aliases it makes it easy to update the models being used by all the workflows.  You can create translate alias, small_model alias,  7B alias, big_model alias.  Basically you can do whatever you want.


I also have a hosts and services file that regulate the connection and the connection strings.  You can also have more than one endpoint on a host and service.  Right now ollama works, I have not had a chance to hook to any of the others, I may have to implement other techniques to make these work for other services. 



So I am making great progress on this tool. I want to get image generation to work for automatic1111 or comfy ui. My dream is to generate all the parts to make a graphic novel with an agent workflow. Story, story board, dialog. 

To Do:

  • add 30 more agents
  • improve agent strings
  • update inputs for the agents
  • build more workflows using agents
  • connect to services 
  • connect to automatic1111 api to create image
  • connect to comfy ui api to create image
  • make a workflow to generate a graphic novel
  • once format of config file settles, write a graphical tool to edit config file
  • implement a rag api and connect to it
  • add more things to this list. :D 

No comments:

Post a Comment