Blog by Saw Win Naung

Official

Explore the Strands Agent Part I


What is Strands?

A Strands Agent is composed of three core components:

Agentic Loop Architecture

Instead of overwhelming the LLM with too many prompts, Strands leverages the LLM’s thought process through what’s called an “agentic loop” architecture:

  1. The agent receives a user request (e.g., “Find unattached EBS volumes that could be removed”).
  2. The LLM analyzes the request and determines the best approach (e.g., “I need to list all EBS volumes and check their attachment status”).
  3. The agent executes the appropriate tools as directed by the LLM (e.g., running AWS CLI commands).
  4. Results are fed back to the LLM for further analysis.
  5. The process repeats until the task is complete.

Strands Doc

Hello World with Strands

Model Context Protocol (MCP)

The Model Context Protocol architecture consists of two key components:

MCP Servers expose four primary capabilities to clients:

Elastic MCP and Tools

Tool NameCore FunctionTypical Use Case by the Agent
1. platform_core_searchBroad Data RetrievalThe go-to tool for finding documents, aggregating data (counting, summing), or performing relevance searches across a known index. It handles flexible natural language queries.
2. platform_core_get_document_by_idSpecific Document RetrievalUsed to fetch the entire raw JSON source of a single log or document when the agent knows its unique ID (e.g., to review the full details of a specific alert).
3. platform_core_list_indicesBasic Index CatalogLists all available indices, aliases, and data streams in the cluster, optionally filtered by a simple pattern (like *logs*).
4. platform_core_index_explorerIntelligent Index DiscoveryCrucial for the agent’s strategy. It takes a natural language query (“authentication logs on Linux servers”) and intelligently recommends the most relevant indices to search. This is the tool that succeeded in your output.
5. platform_core_generate_esqlQuery GenerationTakes a natural language request (e.g., “count the number of login failures by user ubuntu in the last hour”) and translates it into formal ES|QL query syntax.
6. platform_core_execute_esqlQuery ExecutionUsed to run a verbatim ES|QL query directly against Elasticsearch.
7. platform_core_get_index_mappingSchema InspectionRetrieves the mapping (schema) of a specified index, showing all field names and their data types. The agent uses this to understand what fields are available (e.g., user.name, source.ip) before writing complex queries.

Building First Elastic MCP Agent with Strands

from strands import Agent
from strands.models.openai import OpenAIModel
from strands.tools.mcp import MCPClient
from mcp.client.streamable_http import streamablehttp_client
import os
import logging

logging.getLogger("strands").setLevel(logging.DEBUG)

# Sets the logging format and streams logs to stderr
logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s",
    handlers=[logging.StreamHandler()]
)

model = OpenAIModel(
  client_args= {"api_key": os.getenv("OPENAI_API_KEY")},
  model_id= "gpt-4",
  # params={
    # "max_completion_tokens": 1000,
    # "temperature": 0.2,
  # }
)

# Elastic MCP client configuration
MCP_URL = os.getenv("ELASTIC_MCP_URL", "http://localhost:5601/api/agent_builder/mcp")
MCP_APIKEY = os.getenv("ELASTIC_MCP_APIKEY")

elastic_mcp_client = MCPClient(
    lambda: streamablehttp_client(
        url=MCP_URL,
        headers={"Authorization": f"ApiKey {MCP_APIKEY}"},
    )
)
elastic_mcp_client.start()
elastic_tools = elastic_mcp_client.list_tools_sync()

# Display available tools
print("Elastic MCP Tools:")
for tool in elastic_tools:
  print(f"- {tool.tool_name}")

agent = Agent(
    model=model,
    tools=elastic_tools,
    system_prompt=(
        "You are a cybersecurity analyst. Use the Elastic MCP tools to conduct threat hunting "
        "based on the given mission and provide detailed analysis reports."
    )
)

hunt_mission = """
Hunt for any suspicious login activities to Linux servers from unusual locations in the last 7 days.
Provide a summary of findings including any indicators of compromise (IOCs) and recommended remediation steps.
"""

agent(hunt_mission)

The First Invocation

Here’s what happens when the agent executes:

  1. The agent calls the LLM (GPT-4) with the system prompt.
  2. The model invokes the platform_core_generate_esql tool to convert the natural-language hunting request into an ES|QL query. The MCP client runs this tool asynchronously and returns the result, which initially contains a verification error because fields like user.name and src.ip don’t exist in the chosen index.
  3. The logs show that the platform_core_index_explorer tool completed successfully but returned zero relevant indices.
  4. The Elastic MCP agent discovers and loads all available tools, then executes platform_core_list_indices with the default * pattern, receiving the index list from Elasticsearch.
  5. The MCP agent repeatedly tries different Elastic tools to hunt for Linux login events, but each step hits fundamental data-model mismatches: the ES|QL generator fails because expected fields don’t exist in the dataset, the index explorer returns no meaningful Linux-auth indices, and the index list shows only Elastic Agent and Endpoint data streams.
  6. The agent retries with different queries.
  7. After several iterations (7 attempts total), the agent generates a useful ES|QL query and returns data:
FROM logs-endpoint.events.network-default
| KEEP @timestamp, host.name, user.name, source.ip, source.geo.country_name, source.as.number
| LIMIT 100

Interactions

7Th Response

Final Response

The agent successfully identified network events and provided analysis instead of auth log. Interestingly my servers aren’t public-facing (this is my home lab after all), one of the flagged IPs it turned out to be an Ubuntu NTP server..

Output

Next Steps

Moving forward, I plan to:

  1. Optimize the iteration count: The agent made 7 iterations to find the right(I mean meaningful) query, which is excessive. I’ll tweak the Elastic MCP configuration to make it more efficient.
  2. Implement multi-agent architecture: Explore using Swarm to coordinate multiple specialized agents for more efficient.