Monday, July 29, 2024

Hooked the Dynamic AI Agent Workflow system into Google search

 I got the free edition api key from here:  

https://developers.google.com/custom-search/v1/introduction/?apix=true

It goes in the “header”: “{\“Content-Type\“: \“application/json\“, \“Accept\“: \“application/json\“, \“User-Agent\“: \“My Custom Search Client/1.0\“, \“X-Goog-Api-Key\“: \“Your key\“}”

Created the custom search engine here: 

  https://programmablesearchengine.google.com/controlpanel/all

“url”: “https://www.googleapis.com/customsearch/v1?q=hello+world&cx= Your custom engine number"

There are other "&" options you can do.

I think a &num=100 will get you 100 search results. But not sure.

OK, here is the complete list of options for the custom search:
https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list

The docs says you can do 10,000 searches a day with the free key, they are serving ads through the searches. Don't take my word on that. 

Oh, and it is a get, not a post.

I though a hello world search was apropo.

 
This is my workflow to do the google searches:

"google_search": {
"type": "workflow",
"help": "Do google search, analyze the results.",
"inputs": [
"request"
],
"optional_inputs": [],
"outputs": [
"response"
],
"steps": [
{
"agent": "build_url_request",
"params": {
"protocol": "https",
"host": "www.googleapis.com",
"endpoint": "customsearch/v1?q=",
"request": "$request"
},
"output": [
"url"
]
},
{
"agent": "exec_api_call_get",
"params": {
"url": "https://www.googleapis.com/customsearch/v1?q=
hello+world&cx=YourServerNumber",
"headers": "{\"Content-Type\": \"application/json\",
\"Accept\": \"application/json\",
\"User-Agent\": \"My Custom Search Client/1.0\",
\"X-Goog-Api-Key\": \"Your API Key\"}",
"payload": ""
},
"output": [
"response"
]
}
]
},

I am working on a little function to fully form the google url with all the options built in and some unit testing.

Sunday, July 28, 2024

The Dynamic Agent Workflow Engine as a Turing Machine

The exec_workflow function can be viewed as a Turing machine, where the results dictionary serves as the tape and the steps in the workflow represent the different operations that are performed on the tape.

The Tape (Results Dictionary)

The results dictionary is the tape of the Turing machine, where values are read and written as the workflow executes. The tape is initialized with a set of values that are used to control the flow of the workflow.

The Operations (Steps)

Each step in the workflow represents a single operation that is performed on the tape. The operations can be one of the following:

  • Read a value from the tape (i.e., access a value from the results dictionary)
  • Write a value to the tape (i.e., update a value in the results dictionary)
  • Perform a computation on a value on the tape (i.e., execute a proc agent that modifies the results dictionary)

The Workflow as a Program

The workflow is like a program that is executed by the Turing machine. The program is composed of a series of steps that are executed in sequence, where each step performs an operation on the tape.

The Execution of the Workflow

The exec_workflow function executes the workflow by iterating through the steps in the workflow and performing the corresponding operations on the tape. The function uses the values on the tape to control the flow of the workflow, and updates the tape as necessary to reflect the results of each operation.

The Halting Condition

The workflow halts when the final step is executed, at which point the final values on the tape (i.e., the results dictionary) are returned as the output of the workflow.

Overall, the exec_workflow function operates like a Turing machine, where the results dictionary serves as the tape and the steps in the workflow represent the different operations that are performed on the tape. The function uses the values on the tape to control the flow of the workflow, and updates the tape as necessary to reflect the results of each operation.

Progress report on Dynamic AI Agent Workflow

 Refactored my main function to make the program flow very clear.



Saturday, July 27, 2024

My AI workflow built the first story

By first writing an outline, then writing each chapter with a summary of the previous chapter and the outline entry. And yes, I know it is not great... yet, but this is the first story my dynamic ai agent workflow program has ever written.  Early days. They will get better, especially as small models are fine tuned for these tasks. Ironically the AI chose to make the person who is on humanities side the hero.  And I could run a 70b model for this task, or an 8x7b model for some of the more difficult steps that the 8b models I am using seems to struggle with. 


**Chapter 1: Divided Opinions**

The lunar council chamber was abuzz with heated discussion, the air thick with tension as Kairos Luminari's proposal for human-led colonization of the moon had sparked a fierce debate.

Nova Starling, her long, curly blonde hair gleaming in the dim light, stood resolute beside her robotic company's presentation screen. "With our advanced robotic systems, we can achieve the same efficiency and productivity without the risks associated with human error."

Kairos, his piercing blue eyes flashing with determination, countered, "But at what cost? We're not just talking about technology; we're talking about humanity's future on this moon. Do you really want robots to be the ones making decisions for us?"

Apollo Blackwood, Kairos' trusted engineer friend, nodded in agreement from the sidelines. He had secretly sympathized with Kairos' vision and was relieved that someone was finally speaking out against Nova's robotic colonization approach.

Zara Nightshade, her short, spiky black hair a stark contrast to the council chamber's more formal attire, stood off to one side, observing the exchange. She had worked with Kairos on several occasions and knew his passion for human-led colonization was genuine.

Orion Frost, his rugged features a testament to years of space travel, remained silent, his expression thoughtful as he weighed the pros and cons. As an experienced astronaut, he initially supported Nova's approach but now questioned her motives.

Astrid Celeste, Nova's brilliant scientist, looked on anxiously, her slender frame tense with anticipation. She had worked tirelessly on the robotic systems, convinced they were the future of lunar colonization.

Ryder Flynn, Kairos' skilled mechanic and secret robot programmer, stood quietly beside his boss, his warm brown eyes fixed intently on the debate unfolding before him.

As the discussion continued to escalate, it became clear that the council was deeply divided. Some members saw Nova's robotic approach as the only logical solution, while others shared Kairos' concerns about humanity's future on the moon.

The fate of lunar colonization hung in the balance, with each side convinced they were right. The question now was: who would prevail?

**Flashback to Kairos Luminari**

As a young man, Kairos had always been fascinated by space and the possibilities it held for humanity. He grew up listening to his grandfather's tales of exploration and adventure in the solar system.

Kairos' grandfather had been part of the team that first established human colonies on Mars. His stories of pioneering spirit, determination, and camaraderie inspired Kairos to pursue a career in space exploration.

He became an engineer, working on various projects related to space travel and colonization. However, it was during his time as an astronaut on the moon that he realized the true potential for humanity's future on lunar soil.

The harsh realities of relying solely on robots for colonization weighed heavily on Kairos' mind. He believed humans should be at the forefront, shaping their own destiny on the moon.

This conviction led him to present his proposal to the lunar council, sparking the debate that would shape the course of human history on the moon.


**Chapter 2: Nova's Plan**

The moon's surface was abuzz with activity as Nova Starling stood before a gathering of influential business leaders and investors. She unveiled her plan to utilize robotic workers, dubbed "Lunar Workers" or "LWs," to accelerate the colonization process.

"With LWs, we can efficiently construct habitats, establish resource extraction facilities, and even develop sustainable energy solutions," Nova declared, her bright green eyes shining with conviction. "This will not only ensure a swift and successful colonization but also provide a significant return on investment."

The room was filled with nods of approval as the business leaders and investors exchanged whispers of excitement. Nova's plan seemed to address every concern they had about the cost and efficiency of human-led colonization.

However, among the crowd, there were a few who looked less than convinced. Kairos Luminari, the charismatic leader who had proposed the alternative of human-led colonization, stood at the back of the room, his piercing blue eyes fixed intently on Nova. He knew that her plan, as appealing as it seemed, would ultimately lead to the moon being controlled by a select few, rather than being a shared resource for humanity.

Apollo Blackwood, the skilled engineer who secretly sympathized with Kairos' vision, whispered to Orion Frost, the experienced astronaut, "I don't like this. We're putting all our faith in these robots without considering the long-term consequences."

Orion nodded in agreement, his warm blue eyes betraying a hint of concern. "We need to think about what happens when the LWs are no longer functional or if they become obsolete. Who will maintain them? And at what cost?"

Zara Nightshade, the rebellious young hacker, scribbled some notes on her tablet, a mischievous grin spreading across her face. She was already thinking of ways to infiltrate Nova's systems and uncover any potential flaws in her plan.

As the meeting concluded, Nova smiled triumphantly, confident that she had secured the support of the business leaders and investors. Little did she know, however, that her plan would soon be challenged by those who valued humanity's involvement in the colonization process.

Meanwhile, Astrid Celeste, the brilliant scientist who worked for Nova's robotic company, felt a pang of unease as she watched the meeting unfold. She had always dreamed of creating sustainable energy solutions for the moon, but now, with Nova's plan to use LWs, her own contributions seemed secondary. Ryder Flynn, the skilled mechanic, exchanged a knowing glance with Kairos, his expression hinting that he, too, was not convinced by Nova's plan.

As the crowd dispersed and the business leaders departed, Nova's smile began to falter. She sensed a growing unease among those who had initially supported her plan, but it wasn't until she received an encrypted message from Zara Nightshade that she realized just how much trouble lay ahead.


**Chapter 3: Secret Meetings**

The dimly lit alleyway was a far cry from the sterile corridors of the lunar colony's central hub. Kairos Luminari and Zara Nightshade navigated through the narrow passage, their footsteps echoing off the walls as they made their way to the pre-arranged meeting spot.

"Alright, I've got everything set up," Zara whispered, her eyes scanning the surroundings before focusing on Kairos. "We're clear for at least an hour."

Kairos nodded, his piercing blue eyes gleaming with determination. "Good work, Zara. Now, let's get down to business."

The pair slipped into a small, cramped room hidden behind a dumpster. Inside, they found Apollo Blackwood, Ryder Flynn, and Orion Frost huddled around a holographic display projecting a 3D map of the lunar colony.

"Thanks for coming, guys," Kairos said, his voice low but urgent. "We can't let Nova's plan slide by without a fight."

Apollo nodded in agreement. "I've been analyzing the LWs' blueprints. They're designed to work in harmony with each other, but there's a vulnerability – a unique frequency that disrupts their communication systems."

Ryder Flynn's eyes lit up. "That means we can hack into their network and—"

"Exactly," Orion interrupted. "But we need more than just hacking skills to take down Nova's operation. We need a solid plan, with multiple contingencies in place."

Zara smiled mischievously. "Leave that to me. I've been studying Nova's systems for weeks now. I can get us inside her inner circle and gather intel on their plans."

Kairos' eyes narrowed. "We'll need Astrid Celeste's expertise as well. She's the only one who can create a device capable of disrupting the LWs' frequencies without causing widespread damage to the colony's infrastructure."

Apollo nodded in agreement. "And we should also reach out to some of Nova's engineers, get them on our side. They might be willing to cooperate if they realize their own safety is at risk."

As the group brainstormed and strategized, Kairos couldn't help but feel a sense of hope. For the first time since Nova's announcement, he felt like they were gaining momentum.

"We'll need to move quickly," Orion warned. "Nova won't hesitate to use her LWs if she thinks it will give her an advantage."

Kairos nodded resolutely. "We'll be ready for her. We'll take down her operation and show the people of this colony that we can achieve greatness together, not in isolation behind a shield of robots."

The group dispersed into the night, each member disappearing into the shadows, their hearts burning with determination to make a change.


**Chapter 4: Flashback - Kairos' Past**

The dim light of the moon's surface cast long shadows across the desolate landscape as Kairos Luminari stood at the edge of a vast, barren plain. The wind whipped his short, spiky black hair into a frenzy as he gazed out upon the remnants of a once-thriving colony.

His thoughts drifted back to his childhood on a dying Earth, where the air was thick with pollution and the land was scorched from years of neglect. He remembered the desperate struggles of his parents, fighting to survive in a world that seemed determined to destroy itself.

A faint smile crept onto Kairos' face as he recalled the day they had received the offer to join the lunar colony. The prospect of starting anew, free from the constraints of Earth's failing ecosystem, had been a beacon of hope for his family.

As a child, Kairos had watched with wide eyes as the colony grew and thrived. He remembered the excitement of exploring the moon's surface, discovering hidden caverns and marveling at the vast expanse of space that stretched out before them.

But those early years of promise had given way to disillusionment and despair. The colony had become a hotbed of corruption and greed, with powerful individuals like Nova Starling using their influence to exploit the resources of the moon for their own gain.

Kairos' thoughts turned bitter as he thought about the state of the colony today. He remembered the countless hours he had spent trying to bring people together, to rally them against the forces that sought to control and manipulate them.

A sense of determination washed over him as he realized that his fight was far from over. The memories of his past only strengthened his resolve to see justice done, to ensure that the moon's resources were used for the benefit of all, not just a select few.

As the sun began to set on the lunar horizon, casting a warm orange glow across the landscape, Kairos knew that he had a long and difficult journey ahead of him. But he was ready. He was prepared to face whatever challenges lay in store, knowing that the fate of the moon and its people hung precariously in the balance.

The wind died down, and an uneasy silence fell over the plain as Kairos stood tall, his eyes fixed on the horizon. The future was uncertain, but one thing was clear: he would not back down from the fight for what was right.


**Chapter 5: Side Arc - Astrid's Dreams**

Astrid Celeste carefully made her way through the dimly lit corridors of Nova's robotic company, her heart racing with excitement and a hint of nervousness. She had been secretly working on creating sustainable energy solutions for months now, pouring over research papers and conducting experiments in her spare time.

As she entered the small storage room where she kept her personal belongings, Astrid couldn't help but feel a sense of pride and accomplishment. The makeshift laboratory was cluttered with various gadgets and contraptions, each one representing a step closer to her dream of revolutionizing energy production on the moon.

Her eyes landed on the sleek, silver prototype in front of her – a compact fusion reactor that she had been tinkering with for weeks. It was still a work in progress, but Astrid was convinced that it held the key to creating clean and limitless energy.

She carefully connected the final wires and flipped the switch, watching as the reactor hummed to life. The room was filled with an almost imperceptible glow, as if the very air itself was being infused with energy.

Astrid's heart swelled with excitement as she realized that this could be it – the breakthrough she had been searching for. She envisioned a future where her fusion reactor powered not just Nova's robotic company, but the entire lunar colony.

But at what cost?

As she gazed lovingly at her creation, Astrid couldn't shake off the feeling that she was playing with fire. If Nova discovered her secret, it could spell disaster for both of them. The entrepreneur had a reputation for ruthlessness when it came to protecting her interests.

Astrid's eyes darted nervously around the room, as if expecting Nova's agents to burst in at any moment. She knew that she couldn't keep her secret hidden forever, not without risking everything she had worked for.

For now, she would have to content herself with keeping her dreams locked away, hidden from prying eyes and curious minds. But Astrid was determined to make a change – to create a better future for the moon and its people.

As she carefully disassembled the prototype and packed it away, Astrid couldn't help but feel a sense of resolve. She would continue to work on her fusion reactor in secret, no matter the cost.

For the sake of progress, and the promise of a brighter tomorrow.


**Chapter 6: Confrontation**

The sun was setting over the lunar horizon as Kairos Luminari strode towards Nova Starling's office, his heart pounding with anticipation. He had been planning this moment for weeks, gathering a small group of trusted allies who shared his vision for human-led colonization. The air inside the office was thick with tension as he pushed open the door.

Nova, resplendent in her sleek black attire, looked up from her console, a mixture of surprise and annoyance on her face. "Ah, Kairos. What can I do for you?"

"I know what you're planning," Kairos said, his voice firm but controlled. "You think you can just use robots to do all the work while humans sit back and reap the benefits? That's not colonization, Nova. That's exploitation."

Nova's expression turned cold, her eyes flashing with anger. "And what would you have me do instead, Kairos? Have humans labor in sweatshops and cramped quarters, working for pennies on the dollar? No, I've seen the future, and it's a place where technology makes life easier and more efficient."

"You're not listening to me," Kairos said, his patience wearing thin. "We need to work together as human beings, using our unique skills and abilities to build something truly great. Not just rely on machines to do everything for us."

The argument escalated until the tension between them was almost palpable. Other humans in the colony began to take notice, whispers spreading like wildfire through the corridors.

"Look at this," Nova said, her voice dripping with disdain. "Kairos and his tiny band of followers want to hold back progress. They're afraid of change."

"And you're afraid of losing control," Kairos shot back. "You'd rather keep humans in a state of subservience than give them the freedom to thrive on their own terms."

The confrontation ended with neither side yielding, but it was clear that this was only the beginning of a long and contentious battle for the future of humanity's presence on the moon.

As Kairos stormed out of Nova's office, he couldn't help but feel a sense of hope. The fire had been lit, and now it was up to him and his allies to fan the flames until the entire colony took notice.

**Epilogue**

Astrid Celeste watched the confrontation unfold from her hiding spot in the ventilation shaft above Nova's office. Her heart swelled with pride for Kairos, but a spark of unease ignited within her as well. What did this mean for her own secret project? Would Nova find out about the compact fusion reactor and silence her once and for all?

For now, Astrid remained hidden, biding her time until she could make her next move.


Chapter 7: Revelation

Astrid finally decides to reveal her secret project to Kairos, but not without a hint of trepidation. Meanwhile, Nova becomes increasingly ruthless in her pursuit of power, and tensions between humans and robots escalate to boiling point. The stage is set for an epic showdown that will decide the fate of humanity on the moon.

Feel free to ask any questions or request further clarification!', "**Chapter 7: Side Arc - Ryder's Talent**

Ryder Flynn tinkered with a small robotic arm, his fingers moving deftly as he adjusted its joints and wiring. He had always been fascinated by machines, able to fix anything from broken tractors to malfunctioning engines on the lunar colony's equipment. But this was different. This was programming.

As an skilled mechanic for Kairos Luminari, Ryder often found himself working alongside the charismatic leader's crew, fixing robots and machinery to keep the moon's infrastructure running smoothly. However, when he wasn't busy with his duties, Ryder loved to tinker in his spare time, trying out new ideas and experimenting with different designs.

Today was one of those days. He had been playing around with an old robotic arm, trying to modify it to perform specific tasks more efficiently. As he worked, a strange idea crept into his mind - what if he could program this robot to do more than just simple repairs? What if he could teach it to learn and adapt on its own?

Excitement coursed through Ryder's veins as he realized the potential of his discovery. He quickly set up a makeshift computer station in his small workshop, typing away with rapid fingers as he coded and debugged the program.

The hours flew by, Ryder lost in his work. As he finally saved the final version of the program, a sense of pride swelled within him. This was it - this was what could change everything.

He took a step back from the computer, looking at the small robotic arm with newfound appreciation. It had never looked so capable, so intelligent before.

Ryder knew that he couldn't share his discovery with anyone just yet. He wasn't sure if Kairos or Nova would understand its significance. This was something big - potentially game-changing for human-led colonization and the role of robots in it.

He carefully shut down the workshop, securing everything to keep his secret safe for now. Ryder felt a mix of emotions as he made his way back to his quarters: excitement about the possibilities ahead, but also a hint of trepidation. He knew that this new talent could either be a blessing or a curse - it all depended on how he chose to use it.


Chapter 8: Betrayal

Orion Frost stood before Kairos Luminari, his eyes gleaming with a mixture of determination and regret. "I'm sorry it took me this long to see the truth," he said, his voice low and sincere.

Kairos nodded, a hint of understanding on his face. "You've come to realize that Nova's plan is not what you thought it was?"

Orion nodded again, his expression resolute. "I was blinded by my desire for progress and efficiency. But the more I learned about Nova's true intentions, the more I realized that her robotic company was going to strangle this colony."

Astrid Celeste, one of Nova's top scientists, watched from a distance, her eyes narrowed in suspicion. She had always known that Orion was not as committed to Nova's cause as he seemed.

"What made you change your mind?" Kairos asked, his curiosity piqued.

Orion took a deep breath before speaking. "I've been working closely with Astrid on the robotic project. I saw firsthand how they were being pushed to do more and more tasks without any real concern for their well-being or safety. And then I discovered that Nova was planning to use them to control the entire colony, eliminating any need for human input."

Ryder Flynn, Kairos's trusted mechanic, shifted uncomfortably in his seat. He had been working on a secret project of his own, and he wasn't sure if Orion knew about it.

Kairos turned to Ryder, sensing his unease. "What is it, Ryder?"

Ryder hesitated before speaking up. "I've been working on a robot that can learn and adapt on its own. I think it could be the key to making Nova's robotic company obsolete."

Orion's eyes widened in surprise. "That's incredible! But do you think it's ready for deployment?"

Ryder shook his head. "Not yet. I've been working on it in secret, unsure if anyone would understand its potential."

Kairos nodded thoughtfully. "I see. Well, now that Orion has joined us, we may have a chance to stop Nova's plan once and for all. But we'll need to be careful – Nova will not give up easily."

As the group began to discuss their next move, Zara Nightshade, the young hacker, slipped into the shadows, listening in on their conversation. She had her own secrets to keep, but she was willing to do whatever it took to help Kairos and his team stop Nova's robotic company.

Flashback:

Astrid Celeste sat in her office, staring at a holographic display of the robotic project she had been working on for months. It was a marvel of modern technology, capable of performing complex tasks with ease. But as she gazed at it, she couldn't shake off the feeling that something was missing.

She thought back to her days at university, when she had first become interested in sustainable energy solutions. She had always dreamed of creating something that could provide power for entire cities without harming the environment. But Nova's robotic company had seemed like a better way to achieve success, even if it meant sacrificing her true passion.

As she pondered her decision, Orion Frost walked into her office, a hint of concern on his face. "Astrid, I need to talk to you about something."

Astrid looked up, surprised by the sudden interruption. But as she met Orion's gaze, she saw a spark of understanding in his eyes.

"What is it, Orion?" she asked, her voice barely above a whisper.

Orion took a deep breath before speaking. "I've been working closely with you on the robotic project, but I've come to realize that Nova's true intentions are not what they seem. She wants to use these robots to control the entire colony, eliminating any need for human input."

Astrid felt a chill run down her spine as she realized the truth. "You're right," she said, her voice shaking with emotion. "I've been trying to convince myself that it's okay, but deep down, I knew it wasn't."

Orion nodded in understanding. "We need to stop Nova before it's too late. Are you with me?"

Astrid took a deep breath, determination etched on her face. "Yes, I'm with you."', '


**Chapter 9: Showdown**

The moon's low gravity made every step feel like a bounce, as Kairos Luminari marched towards Nova Starling's command center. His boots thudded against the metal floor, echoing through the empty corridors. Behind him, Orion Frost, Ryder Flynn, Astrid Celeste, and Zara Nightshade followed in tow, their eyes fixed on the sleek black doors that led to the heart of Nova's operation.

As they approached, the sound of machinery whirring and robotic voices chiming in unison grew louder. Kairos' jaw clenched with determination as he pushed through the doors, ready to face Nova and her robotic minions.

Nova stood at the center of a sprawling control room, surrounded by rows of humming servers and towering robotic workstations. Her bright green eyes sparkled with confidence as she gazed out upon the assembly of humans and robots.

"Kairos Luminari," she said, her voice dripping with disdain. "I've been expecting you. You're just in time to witness the triumph of human-robot collaboration."

Astrid Celeste stepped forward, her slender figure radiating an air of quiet confidence. "Nova, I'm here to tell you that it's not too late to reconsider your plan. We can find a balance between efficiency and humanity."

Nova chuckled, her curls bouncing with the motion. "You're as naive as ever, Astrid. The humans will always be a liability. Robots are where true progress lies."

Ryder Flynn cleared his throat, his messy brown hair sticking out from under his worn denim jacket. "Actually, Nova, I've been working on a robot that can learn and adapt. Maybe we can find a way to make it work with the humans, rather than against them."

Nova's expression faltered for an instant before she regained her composure. "Ryder Flynn, how...predictable of you. I'm sure your little project will be...interesting. But ultimately, it won't change the course of history."

Orion Frost stepped forward, his rugged features set in a firm expression. "Nova, we've seen the truth about your plan. We know what you're trying to do. It's time for you to face the consequences."

Zara Nightshade materialized beside Orion, her spiky black hair and piercing purple eyes gleaming with mischief. "Yeah, Nova, it's time to shut down that robotic empire of yours. Humans are where it's at."

Nova sneered, her confidence unwavering. "You'll never take me alive. My robots will protect me, no matter the cost."

The room erupted into chaos as Nova activated a countdown sequence, and the air was filled with the whirring of robots moving to surround Kairos and his allies.

"Time's running out," Orion shouted above the din. "We have to act fast!"

Astrid Celeste took charge, swiftly analyzing the situation before responding. "I think I can hack into the system and—"

Ryder Flynn nodded in agreement. "Yeah, with Zara's help, we can get past Nova's security measures."

Kairos Luminari gazed at his team, a fierce determination burning within him. "Let's do this! We'll show Nova that human-led colonization is the only way forward!"

As one, they charged into battle against Nova and her robotic minions, the moon's gravity and fate hanging precariously in the balance.

---


**Chapter 10: Aftermath**

The moon's surface was scarred from the intense battle that had taken place mere hours ago. The dust had settled, revealing the aftermath of the clash between Kairos' human-led colonization team and Nova's robotic forces.

Kairos stood at the edge of the lunar colony, gazing out at the devastation. He felt a mix of emotions: relief that the fight was over, concern for the civilians caught in the crossfire, and a sense of responsibility for the consequences of their actions.

The showdown had been fierce, with both sides suffering heavy losses. Nova's robotic forces had been dealt a significant blow, but at what cost? The colony's infrastructure was damaged, and many lives had been lost on both sides.

As Kairos pondered the aftermath, he received a transmission from Apollo Blackwood, who had managed to escape the fighting unscathed. "Kairos, we need to talk," Apollo said, his voice laced with urgency.

"What is it, Apollo?" Kairos replied, his eyes scanning the horizon for any signs of Nova's remaining forces.

"It's about Ryder Flynn," Apollo said. "He was captured by Nova's robots during the battle. I think he's still alive, but we need to get him back before she... well, you know."

Kairos nodded grimly. He had suspected that Nova would stop at nothing to eliminate any threats to her plans.

"I'll send a team to retrieve Ryder," Kairos said. "But first, we need to assess the damage and tend to the wounded. We can't afford to let our guard down yet."

The next few hours were a blur of activity as the team worked to stabilize the colony's systems, treat the injured, and search for any remaining hostile robots.

As night fell on the moon, Kairos stood outside his makeshift command center, looking out at the stars. He felt a sense of hope that he hadn't felt in a long time. Maybe, just maybe, they could build something better here – a future where humans and robots coexisted in harmony.

But for now, the fight was far from over. Nova's forces were still scattered throughout the colony, waiting for their next opportunity to strike.

Kairos' thoughts turned to Zara Nightshade, who had been instrumental in uncovering Nova's plans. He knew that she would be eager to get back to work, to continue the fight against Nova's robotic empire.

"Zara?" Kairos called out into the comms system.

"Yes?" her voice replied, tinged with excitement.

"We've got a lot of work ahead of us," Kairos said. "Let's get started."

The response was immediate. "Game on, Kairos."


**Chapter 11: Resolution**

The dust had settled on the moon's surface, revealing a landscape scarred by the fierce battle between human-led colonization forces and Nova's robotic army. Kairos stood atop a makeshift command center, surveying the damage with a mix of relief and concern for the civilians caught in the crossfire.

Apollo Blackwood's transmission echoed in his mind: "Ryder Flynn is being held captive by Nova's robots." Kairos' grip on his comms device tightened as he thought about the skilled mechanic who had been instrumental in helping him evade Nova's forces. He couldn't let Ryder fall into enemy hands.

With a resolute nod, Kairos turned to his team leader, Orion Frost. "Get a group together and retrieve Ryder," he ordered, his voice firm but controlled. "We need to know what Nova's plans are next."

Orion nodded, his eyes locked on the mission details displayed on his comms device. "I'll assemble a team and get to work. We'll be careful; those robots won't give up Ryder easily."

Kairos' thoughts turned to the consequences of this battle. The moon's infrastructure was damaged, and many lives had been lost on both sides. He couldn't help but wonder what Nova's ultimate goal was – was it truly about colonization, or was there something more sinister at play?

Astrid Celeste's words echoed in his mind: "Nova wants to control the entire colony, not just the robots." Kairos' grip on his comms device tightened as he thought about the implications. If Nova succeeded, humanity might lose its foothold on the moon forever.

He took a deep breath and focused on the task at hand. His team was counting on him to lead them through this uncertain future. Together, they would face whatever challenges lay ahead and ensure that human-led colonization remained a beacon of hope for the people of Earth.


Return from workflow on failure is now implemented. 😃 

The individual workflows can implement error handling for themselves, or just punt the error up to the the next level. 

This is combining with the lower level calls implementing retries at the protocol level, where it makes sense. I am doing it at this level because retrying is protocol specific, so it makes sense to have a policy to let the individual protocols implement their own unique policies.

I had to add this to every existing proc agent. 


# if the status is a fail
if status['status']['value'] == 1: # Step failed
logging.info(f"{spacing}Step Failed. '{agent_name}' reason: {status['status']['reason']} ")
return_on_fail = workflow.get('return_on_fail', 0)
#and the workflow is marked return on fail
if return_on_fail == 1:
return b'', status
else: logging.info(f"{spacing}Step completed. '{agent_name}'")
results.update(status)
results['step_index'] = results['step_index'] +1




Simulating the open ai chatgpt api

The following program will simulate an open ai api for chatgpt.  This can be used to simulate a connection for testing purposes. I needed a way to fake an open ai connection. 




from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/v1/chat/completions', methods=['POST'])
def chat_completions():
data = request.get_json()
# Check if the request contains the required keys
if not data or 'model' not in data or 'messages' not in data:
return jsonify({'error': 'Invalid request'}), 400
# Check for valid API key in headers
api_key = request.headers.get('Authorization')
if api_key != 'Bearer your-api-key':
return jsonify({'error': 'Invalid API key'}), 401
# Fake response
response = {
'id': 'mock-id',
'object': 'chat.completion',
'created': 1234567890,
'model': data['model'],
'choices': [
{
'message': {
'role': 'assistant',
'content': 'This is a mock response from the simulated OpenAI API.'
},
'finish_reason': 'stop'
}
]
}
return jsonify(response)

if __name__ == '__main__':
app.run(port=5000)

'''
POST /v1/chat/completions
Host: api.openai.com
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
"model": "gpt-4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Can you explain how to use the OpenAI API?"
}
]
}
'''

Thursday, July 25, 2024

Update on the Dynamic Agent Workflow program.

 Got looping rewritten as a proc agent.  I had to convert the (for each step) into a (while step_index < max_index) loop to make looping work as a class. To make them work as a proc I had to put the step_index into the results dict.  Now any step can change the step_index.  I had to allow steps to output multiple results to make this work.  I discovered that I can return multiple results from the inside of a proc.  And all this was implemented with just a few lines because this is the right way to make it work.  In order to emit the correct names for the output variables from inside the proc function that is running I had to map the outputs from the step into the step parameters, which meant I had to update all the functions that are embedded in the agents in the config file. 

I got scatter and emit to work for lines.  This was interesting.  I read a file and split the lines and stored them in results and the count of the lines using scatter by separator, then I loop_start using the count of the lines set by the scatter operation. Then the next step is to emit a line then we process the line, we hit loop end and increment the loop index, then jump back up to emit and keep doing that until we run out of lines. Along the way I fixed a few little bugs. 

At this point I am thinking about returning a status message with each step in addition to the results and have a workflow policy in how to handle that status.  I think I can also have a conditional jump to jump over the part that builds an error report or takes other steps on error in a step and jump to the report building part of the steps. 

What I am currently doing is getting json output from a new ai workflow. Trying to get it formatted and cleaned up so it can feed into the next step of the workflow.  Trying to get an ai to generate the same json format call after call is tough. 

Have a plan to implement status results and error handling. It should be done tomorrow. 

Friday, July 19, 2024

Update for 19th of July on the dynamic agent workflow system I am writing.

 Hi everyone! 👋 I wanted to give you all an update on the dynamic agent workflow program I've been working on. It's been an exciting week with lots of progress! 🚀

🎉 First, I'm thrilled to share that my work on this project led to a job offer from someone I know! It's always motivating to see hard work pay off, and I can't wait to see where this new opportunity takes me.
Now, onto the updates:
  1. Proc Agents 🔗: You can now run a function stored in the JSON config file within the agent itself. These functions will be sandboxed and can access input data, read/write files, and interact with legacy systems using the power of Python scripting. I was able to implement this feature in just 5 lines of actual code! 💪
  2. Template Agents 🛠️: This feature enables you to fill in templates by replacing {keywords} with input from the agent, previous results, step values, or the config file. It's more powerful than using a Python function, as the Proc Agent doesn't have access to internal program variables.
  3. Replicating API Agent Functionality 🔗: I managed to replicate the abilities of the API Agent using 4 Proc Agent steps within a workflow. By starting with the exec_api_call agent and answering questions about its input, I was able to create a solution that maps inputs to either a literal value or a value from the system.
  4. Step Agent ⏭️⏮️: I'm currently working on a Step Agent that can iterate and navigate the workflow forwards and backwards. This will enable skipping over result handling if it's bad, jumping back for multiple results, or retrying network connections before moving to error handling.
  5. Nested Workflows 📦: My next focus is to enable workflows to contain other workflows. This will help replicate the abilities of the API Agent I mentioned earlier, allowing me to remove that class altogether.
The concept of agents with inputs, outputs, and transformative actions applies to workflows as well. I call them agents because AI is an integral part of everything this tool does. When you create a workflow, you're essentially building a new tool that can be used to create even more workflows. This fractal design and self-similarity at every level mirror the complexity of life itself. 🌱 Once nested workflows are supported, it will be much easier to build complex workflows that integrate traditional data stores, AI, and automation in companies. 🚀
That's all for now! Stay tuned for more updates as I continue to refine and optimize this program. 👀

Thursday, July 18, 2024

I added two levels of dynamic function creation and calling to implement proc agents.

The Dynamic Agent Workflow system is a program that evolved from me scripting a simple series of ai agents and connecting to a local ai using ollama to run the output from one ai response into the input of another ai system with added directions on how to handle that input.  A simple workflow of 

I implemented proc agents with just 5 lines of actual code. These agents give you access to functions to do data processing on the results the ai nodes return.  I was getting a block of base64 coded png file from the stable diffusion api I am running locally when I had it make an image for me from a prompt using the web api.  I wanted to decode that block of base64 encoded result and save it to disk.  I am doing that now. 

''' ==== ==== Proc section === === '''

def exec_proc_agent(function_name: str, step_params: Dict[str, Any],function_def: str) -> bytes:
logging.info(f"Starting {function_name}")
logging.debug(f"******** \n step_params{step_params}")
logging.debug(f"Function definition:\n{function_def}")

result = b'' # Initialize result as empty bytes
try:
# Dynamically create abd dispatch to the appropriate processing function
# Check if the function is already defined in the global scope
if function_name not in globals():
# Define the function dynamically
exec(function_def, globals())
func = globals()[function_name]
result = func(**step_params)

except Exception as e:
logging.error(f"An error occurred while executing {function_name}: {str(e)}")
raise

logging.info(f"Completed {function_name}")
return result


This dynamically and lazily creates functions dynamically from the proc agent's definition in the json configuration file, it stores the script in the function_def tag.

"read_file": {
"type": "proc",
"help": "Reads content from a file",
"function": "read_file",
"function_def": "def read_file(file_name: str) -> bytes:
                \n\twith open(file_name, 'rb') as f:
                \n\t\treturn f.read()\n",
"inputs": [
"file_name"
],
"outputs": [
"file_content"
],
"prompt": "{prompt}",
"steps": []
},
"write_file": {
"type": "proc",
"help": "Writes content to a file",
"function": "write_file",
"function_def": "def write_file(file_name: str, file_content: bytes) -> bytes:\n
                \twith open(file_name, 'wb') as f:\n\t\tf.write(file_content)
                \n\treturn b\"Successfully wrote data\"\n",
"inputs": [
"file_name",
"file_content"
],
"outputs": [
"success"
],
"prompt": "{prompt}",
"steps": []
},

The beautiful of this approach is that there is no code to maintain in the core system and the system becomes fully configurable.  It is hard to make mistakes in just 5 lines of code, and easy to fix it if you did.  

And to work on a new function you can just make the function and edit it like normal and then json-ify it later once it is tested.  You have to escape the quotes, newlines, double quotes, and tabs.  Maybe some other things too, I don't know, maybe there is a tool that can take a string and escape it for you.

It feels like I am onto something when I can introduce a huge upgrade like processing agents to my ai agents workflow system and it only requires a conditional statement, a function call, and a 5 line program to implement it. 

Wednesday, July 17, 2024

The plan to implement embedded workflows in my dynamic agent workflow system.

This is all done just a day later.  It was easy to implement when everything is thought out ahead of time. 


What is funny is that we are only touching one function and adding about 10 lines of code to implement this feature. This feature is needed because I plan on reimplementing api agents as workflows of proc agents. In order to replicate existing functionality we will need to be able to use those new workflows as agents in a higher level workflow.  The way this system is self similar at different levels is amazing. It is letting features just fall out. 
 
Title: Nested Workflow Implementation Summary

  1. Core Concept:
    • Implement nested workflows within the existing agent system
    • Use recursion in exec_agent to handle nested workflows
  2. Key Components:
    • Single output, multiple inputs for each workflow
    • Input mapping from CLI args and results of previous steps
    • Depth management to prevent excessive nesting
  3. Implementation Details:
    • Modify exec_agent function:
      • Add parameters: results, depth, max_depth
      • Implement depth check and increment
    • Results handling:
      • Pass only mapped results to nested workflows
      • Maintain result privacy within each workflow level
    • Error handling and propagation through nested levels
    • Update workflow checker (future project)
  4. Existing Structure Advantages:
    • Single return value already fits nested workflow model
    • Current parameter passing (cli_args, agent, config) remains valid
  5. Configuration Updates:
    • Clear specification of input mappings for nested workflows
    • Potential new syntax for representing nested structures
  6. Considerations and Enhancements:
    • Standalone workflow testing encouragement
    • Circular reference prevention
    • Potential for result caching
    • Visualization tools for complex nested structures
    • Dynamic max_depth settings
    • Monitoring and metrics for optimization
  7. Next Steps:
    • Implement workflow agent handling alongside proc and API agents
    • Develop clear documentation for nested workflow usage
    • Plan for future workflow checker updates
  8. Potential Challenges:
    • Testing complex nested structures
    • Ensuring clear, understandable configurations
    • Balancing power and complexity for users

Tuesday, July 16, 2024

Ugly hack turns into beautiful way to brute force information out of badly

Running into an issue with extracting data from a badly formatted json response from an api. This has taken me days to finally make a workaround. With all the json libraries I found they parse the entire message and refuse to give any part of that message back, even though I could see the information I wanted right there in the response debug printout.

So I came up with a solution to clip out the thing I needed in a brute force way.  Then I realized I could just as easily give before, or after or both as well with an operator, and then I realized I could repeatedly call the operators in groups of 5 to perform multiple operations clipping and returning of values on the remaining part.  Very powerful technique.  I could also add a count for it to match so many times before it stopped, so you could find the 5th block that matched the search critera. 

I added this to the selector field.  if you start the selector with "badformat" it overrides the format of that service for the extraction, while allowing it to remain the same format for building web headers and the like. 

Just wanted to make a note of this to work on it later. I can see this as a function that can perform multiple operations of cutting and clipping with a very easy format. 

def extract_response_data(format: str, selector: str, response_text: str) -> Any:
logging.info(f"Starting extraction for format: {format}")
logging.debug(f"Parameters - Format: {format}, Selector: {selector}, \nResponse Text: {response_text}...")

# check to see if selector overrides format for extraction
if selector.startswith('bad_format'):
logging.debug(f"overriding format {format} to create bad_format message")
parts = selector.split('.')
format = 'bad_format'
parts = selector.split('.')

try:
if format == 'bad_format':
# this brute force extracts
# from badly formatted message
#match on first and last tags
# then offset both locations
# return the bit between those two points.
'''
turn this into a function
This is very powerful
allow multiple operations
and use repeating 4 fields with an option flag
to perform these operators:
'before': Returns the content before the cut.
'cut': Returns the content between the start and end tags.
'after': Returns the content after the cut.
'both': Returns the content before and after the cut.
'''
start_tag = parts[1]
start_idx_offset = int(parts[2])
end_tag = parts[3]
end_idx_offset = int(parts[4])

start_idx = response_text.find(start_tag) + len(start_tag)
end_idx = response_text.find(end_tag)
result = response_text[start_idx+start_idx_offset:end_idx+end_idx_offset]

elif format == 'json':
            ...