Model-Driven AI Agents: Building Sophisticated Tools with Strands-Agents/sdk-python


Model-Driven AI Agents: Building Sophisticated Tools with Strands-Agents/sdk-python

strands-agents/sdk-python

2025-12-14

This SDK is particularly exciting because it allows you to build sophisticated AI agents using a model-driven approach with minimal code.

From a software engineer's viewpoint, strands-agents/sdk-python offers several key benefits that simplify complex AI development

The traditional way of building an agent involves a lot of boilerplate code for managing tool calling, conversational history, state, and complex LLM prompting (like few-shot examples or RAG). This SDK abstracts away much of that complexity. You only need to define the agent's behavior using a model (like a structured configuration), and the SDK handles the rest. This drastically speeds up development.

Agents often need to produce structured data (e.g., JSON) to trigger downstream systems or actions. The SDK enforces this structure, making the agent's output more reliable and easier for your application code to consume. This reduces the time spent on parsing and validation.

AI agents need to interact with the real world (databases, APIs, services) through "tools" or "functions." The SDK provides a clear and straightforward way to define and inject these tools, allowing the agent to decide when and how to use them to fulfill a request.

You can install the SDK using pip.

pip install strands-agents-sdk

The core concept is creating an Agent instance and then defining its Model and Tools.

Here is a comprehensive example demonstrating how to build a simple "Weather & Date Agent" that can answer questions using both internal knowledge and external tools.

We'll define two simple Python functions that the agent can "call" as tools.

from datetime import datetime
import json

# Tool 1: Gets the current date and time
def get_current_datetime() -> str:
    """Returns the current date and time in ISO format."""
    return datetime.now().isoformat()

# Tool 2: Simulates fetching weather data for a city
def get_city_weather(city: str) -> str:
    """
    Fetches the current weather for a specified city.
    Args:
        city: The name of the city (e.g., 'Tokyo', 'London').
    """
    if 'tokyo' in city.lower():
        return json.dumps({"city": "Tokyo", "temperature": "25C", "condition": "Sunny"})
    elif 'london' in city.lower():
        return json.dumps({"city": "London", "temperature": "12C", "condition": "Cloudy"})
    else:
        return json.dumps({"error": "Weather data not available for this city"})

We instantiate the agent and pass it the tools it can use.

from strands_agents_sdk.agent import Agent

# IMPORTANT: You need to set up your LLM environment variables (e.g., OPENAI_API_KEY)
# The Agent class will automatically detect and use the LLM provider.

# List of tools the agent can use
tools_list = [get_current_datetime, get_city_weather]

# Initialize the Agent
# The 'model' argument specifies the LLM to use (e.g., 'gpt-4o' or 'claude-3-opus')
agent = Agent(
    tools=tools_list,
    model="gpt-4o"  # Use a powerful model for best tool-use capability
)

print(" Agent initialized with two tools: get_current_datetime and get_city_weather.")

Now we can ask the agent questions. The key here is that the agent decides whether to answer directly or to first use a tool.

user_prompt_1 = "What is the weather like in London right now?"

print(f"\n--- User Prompt 1: {user_prompt_1} ---")
# The .invoke() method runs the agent
response_1 = agent.invoke(user_prompt_1)

# The response object contains the final answer and any tool calls made
print(f"\nFinal Agent Response:")
print(response_1.answer)
print("\n--- Tool History ---")
# If the agent used a tool, the details will be in the response's history
for call in response_1.history:
    if call.tool_call:
        # The agent decided to call this function
        print(f"-> Agent called Tool: {call.tool_call.function_name}")
        print(f"-> Arguments: {call.tool_call.args}")
        # This is the actual output from the Python function
        print(f"-> Tool Output: {call.tool_result.content}")

# Expected output: The agent calls get_city_weather('London'), gets the JSON,
# and then summarizes the result: "The weather in London is 12C and Cloudy."
user_prompt_2 = "Hello! What is your purpose?"

print(f"\n--- User Prompt 2: {user_prompt_2} ---")
response_2 = agent.invoke(user_prompt_2)

print(f"\nFinal Agent Response:")
print(response_2.answer)
print("\n--- Tool History ---")
# This time, the history will be empty or contain only the initial prompt
print("No tools were called for this request.")

# Expected output: The agent answers directly without using any tools,
# e.g., "I am an AI assistant designed to help you with dates and weather information."

The strands-agents/sdk-python library is essentially a high-level framework for orchestration.

FeatureSoftware Engineering Benefit
Declarative ToolingYou define what a tool does (via its function signature and docstring), and the SDK/LLM handles when to call it.
State ManagementSimplifies complex conversational flows and memory, allowing you to focus on business logic.
Model AbstractionEasily swap out the underlying LLM (e.g., from GPT-4o to Claude) without rewriting your agent logic, fostering future-proofing.

It allows you to transition from writing explicit, sequential programming (e.g., if-else blocks to check for user intent) to a declarative, intent-driven system where the LLM becomes the central routing engine.


strands-agents/sdk-python




The Engineer's Path: Understanding LLMs by Building Them

The project you've pointed out, "rasbt/LLMs-from-scratch, " is a fantastic resource. As a software engineer, you might be wondering


Daft Explained: The Python/Rust Distributed Engine for ML Engineers

At its core, Daft is a distributed query engine that's built for modern data science and machine learning workflows. Think of it as a powerful


A Software Engineer's Guide to OpenBB: Unleashing Financial Data with Python

OpenBB is an open-source platform that provides investment research tools. Think of it as a comprehensive toolkit that brings together various financial data sources


Code Your Next YouTube Hit: Leveraging LLMs for Instant Video Creation

This project is a fascinating example of applying AI and automation to content creation. It's essentially a tool that takes a topic and churns out a finished


The Lightweight Framework for Collaborative AI Agents

This framework is a lightweight, powerful Python SDK (Software Development Kit) from the developers of GPT models, designed specifically for creating multi-agent workflows


Mastering Diffusion with ComfyUI: An Engineer's Guide

ComfyUI offers several significant advantages for software engineersUnparalleled Control and Flexibility Unlike many other diffusion model UIs that abstract away the underlying process


Scaling AI Solutions with Agent SQUAD: An Engineer's Perspective

From a software engineer's perspective, Agent SQUAD is a powerful tool for building multi-agent systems. Instead of having one monolithic AI model handle everything


Microsoft Agent Framework: Orchestrating Multi-Agent AI Workflows in Python and .NET

Here's a friendly, detailed breakdown from a software engineer's perspective.At its core, the Microsoft Agent Framework is a set of libraries and conventions that help you create AI agents and manage complex interactions between them


Unlock Your Knowledge Base: A Software Engineer's Guide to DocsGPT

At its core, DocsGPT is an open-source tool that leverages generative AI to provide reliable answers from your documentation and knowledge bases


Bridging the Gap: Software Engineering to AI Development

The ai-engineering-hub repository is a great resource for software engineers looking to dive into the world of AI and machine learning