VOOZH about

URL: https://thenewstack.io/building-autonomous-systems-in-python-with-agentic-workflows/

⇱ Building Autonomous Systems in Python with Agentic Workflows - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2025-01-29 07:00:30
Building Autonomous Systems in Python with Agentic Workflows
sponsor-andela,sponsored-post-contributed,tutorial,
AI / AI Agents / CI/CD / Python

Building Autonomous Systems in Python with Agentic Workflows

Agentic workflows act as intelligent agents capable of solving problems, streamlining processes and driving efficiency at a higher level.
Jan 29th, 2025 7:00am by Oladimeji Sowole
👁 Featued image for: Building Autonomous Systems in Python with Agentic Workflows
Image from drmvisioner on Shutterstock
Andela sponsored this post.
As businesses and technology push boundaries, staying ahead often means finding more innovative, faster ways to get work done. Enter agentic workflows, a revolutionary approach to task automation that empowers systems to analyze, decide and execute tasks independently. Agentic workflows are not just another tech buzzword; they are about enabling automation that doesn’t just follow a script but adapts in real time to handle complex challenges. Traditional automation tools follow predefined steps. They’re effective for routine, repetitive work but falter when faced with dynamic, evolving tasks. This is where agentic workflows stand out. They combine flexibility and intelligence to manage complex operations with minimal manual input. By incorporating tools like large language models (LLMs), APIs and other external resources, these workflows act as intelligent agents capable of solving problems, streamlining processes and driving efficiency at a higher level. For most organizations, this is a game-changer. Agentic workflows can reduce repetitive workloads, reduce error rates and speed up decision-making. When deployed effectively, they drive innovation, allowing teams to focus on high-value tasks while autonomous systems handle the details. To put it simply, agentic workflows make your organization more agile, adaptive and future-ready.

What Are Agentic Workflows?

Agentic workflows are systems composed of autonomous agents working collaboratively to achieve specific goals. Each agent in the workflow is designed to:
  1. Perceive its environment or context.
  2. Make decisions based on predefined rules or models.
  3. Execute tasks, often by interacting with external APIs or systems.

Key Benefits:

  • Automation: Reduce manual effort by delegating tasks to agents.
  • Adaptability: Agents can dynamically adjust to changing requirements or input.
  • Efficiency: Optimize multistep tasks by intelligently delegating subtasks.

Common Use Cases:

  • Customer support bots with escalation workflows.
  • Autonomous research assistants that retrieve, analyze and summarize information.
  • Workflow orchestration for IoT devices in smart homes.

Step 1: Setting Up the Environment

Before you begin building your agentic workflow, ensure the required tools are installed. We’ll use OpenAI for natural language processing and Langchain for workflow orchestration.

Install Dependencies:

pip install openai langchain requests

Configure OpenAI API Key:

Store your API key securely using environment variables:
import os

# Set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "your_openai_api_key"

Step 2: Designing the Workflow

For this tutorial, we’ll build an autonomous research agent workflow. The workflow involves:
  1. Accepting a research topic as input.
  2. Retrieving relevant web articles using an external API.
  3. Summarizing the content.
  4. Storing the results in a local file.

Step 3: Creating the Agent Framework

Agents need a core structure to perceive, decide and act. Let’s build this framework step by step.

Basic Agent Class

Define a reusable Agent class that all agents will inherit.
class Agent:
 def __init__(self, name):
 self.name = name

 def perceive(self, input_data):
 """Receive input from the environment."""
 raise NotImplementedError("Perceive method must be implemented.")

 def decide(self):
 """Make decisions based on perceived input."""
 raise NotImplementedError("Decide method must be implemented.")

 def act(self):
 """Perform an action based on the decision."""
 raise NotImplementedError("Act method must be implemented.")

Step 4: Implementing Specialized Agents

We will create three specialized agents:
  1. Input agent: Accepts the research topic.
  2. Retrieval agent: Fetches articles from an API.
  3. Summarization agent: Summarizes the content.

Input Agent

This agent takes a research topic as input.
class InputAgent(Agent):
 def perceive(self, input_data):
 self.topic = input_data

 def decide(self):
 return f"Proceeding with research on: {self.topic}"

 def act(self):
 print(self.decide())
 return self.topic

Retrieval Agent

This agent uses an external API (such as a mock news API) to fetch articles.
class RetrievalAgent(Agent):
 def __init__(self, name, api_url):
 super().__init__(name)
 self.api_url = api_url

 def perceive(self, topic):
 self.topic = topic

 def decide(self):
 query_params = {"q": self.topic, "apiKey": "your_api_key"}
 return requests.get(self.api_url, params=query_params)

 def act(self):
 response = self.decide()
 if response.status_code == 200:
 articles = response.json().get("articles", [])
 print(f"Retrieved {len(articles)} articles.")
 return articles
 else:
 print("Failed to retrieve articles.")
 return []

Summarization Agent

This agent uses OpenAI’s API to summarize the content.
import openai

class SummarizationAgent(Agent):
 def perceive(self, articles):
 self.articles = articles

 def decide(self):
 summaries = []
 for article in self.articles:
 prompt = f"Summarize the following article:\n\n{article['content']}"
 response = openai.Completion.create(
 model="text-davinci-003",
 prompt=prompt,
 max_tokens=100
 )
 summaries.append(response.choices[0].text.strip())
 return summaries

 def act(self):
 summaries = self.decide()
 for idx, summary in enumerate(summaries):
 print(f"Summary {idx + 1}: {summary}")
 return summaries

Step 5: Orchestrating the Workflow

Now, let’s integrate the agents into an orchestrated workflow.
class Workflow:
 def __init__(self, agents):
 self.agents = agents

 def run(self, input_data):
 current_data = input_data
 for agent in self.agents:
 agent.perceive(current_data)
 current_data = agent.act()
 print("Workflow completed.")

Instantiate Agents and Run the Workflow

# Define the API URL for article retrieval
api_url = "https://newsapi.org/v2/everything"

# Create agents
input_agent = InputAgent(name="InputAgent")
retrieval_agent = RetrievalAgent(name="RetrievalAgent", api_url=api_url)
summarization_agent = SummarizationAgent(name="SummarizationAgent")

# Orchestrate workflow
agents = [input_agent, retrieval_agent, summarization_agent]
research_workflow = Workflow(agents)

# Run the workflow
topic = "AI in Healthcare"
research_workflow.run(topic)

Step 6: Enhancing the Workflow

You can extend the functionality of this workflow by: Adding file storage: Save the summarized content to a text file.
class FileStorageAgent(Agent):
 def perceive(self, summaries):
 self.summaries = summaries

 def decide(self):
 return "Summaries saved to research_summaries.txt."

 def act(self):
 with open("research_summaries.txt", "w") as file:
 for summary in self.summaries:
 file.write(summary + "\n\n")
 print(self.decide())

Add this agent to the workflow:
file_storage_agent = FileStorageAgent(name="FileStorageAgent")
agents.append(file_storage_agent)

Error handling: Implement exception handling for API errors and empty responses. Parallel processing: Use Python’s asyncio to process multiple articles concurrently.

Step 7: Testing and Debugging

Test the workflow with various topics to ensure robustness:
  • Handle topics with no articles available.
  • Test with diverse inputs to verify agent adaptability.
  • Log errors for easier debugging.

Conclusion

Agentic workflows offer a practical approach to creating smart, task-oriented systems. By breaking tasks into specialized components, you can build scalable, flexible solutions for handling complex processes. By following this step-by-step guide, you’ve mastered the basics of designing and implementing agentic workflows with Python. From setting up individual agents to coordinating them into a unified system, you now have the tools to develop autonomous workflows that fit your specific needs. Take the next step by experimenting with more advanced agents, integrating additional tools and APIs, and refining decision-making processes to maximize the potential of these workflows. Revolutionize the way you work with cutting-edge AI innovation. Explore Andela’s definitive guide “3 AI tools transforming productivity.”
Andela provides the world’s largest private marketplace for global remote tech talent driven by an AI-powered platform to manage the complete contract hiring lifecycle. Andela helps companies scale teams & deliver projects faster via specialized areas: App Engineering, AI, Cloud, Data & Analytics.
Learn More
The latest from Andela
Hear more from our sponsor
TRENDING STORIES
Oladimeji Sowole is a member of the Andela Talent Network, a private marketplace for global tech talent.  A Data Scientist and Data Analyst with more than 6 years of professional experience building data visualizations with different tools and predictive models...
Read more from Oladimeji Sowole
Andela sponsored this post.
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Class, Receive, OpenAI.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.