Skip to content

Commit faa6838

Browse files
poshinchenjsamuel1
authored andcommitted
chore: allow custom agent name (strands-agents#347)
1 parent d8b3cfd commit faa6838

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/strands/agent/agent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class _DefaultCallbackHandlerSentinel:
5656

5757

5858
_DEFAULT_CALLBACK_HANDLER = _DefaultCallbackHandlerSentinel()
59+
_DEFAULT_AGENT_NAME = "Strands Agents"
5960

6061

6162
class Agent:
@@ -320,7 +321,7 @@ def __init__(
320321
self.state = AgentState()
321322

322323
self.tool_caller = Agent.ToolCaller(self)
323-
self.name = name
324+
self.name = name or _DEFAULT_AGENT_NAME
324325
self.description = description
325326

326327
self._hooks = HookRegistry()
@@ -710,6 +711,7 @@ def _start_agent_trace_span(self, prompt: str) -> None:
710711

711712
self.trace_span = self.tracer.start_agent_span(
712713
prompt=prompt,
714+
agent_name=self.name,
713715
model_id=model_id,
714716
tools=self.tool_names,
715717
system_prompt=self.system_prompt,

src/strands/telemetry/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def end_event_loop_cycle_span(
406406
def start_agent_span(
407407
self,
408408
prompt: str,
409-
agent_name: str = "Strands Agent",
409+
agent_name: str,
410410
model_id: Optional[str] = None,
411411
tools: Optional[list] = None,
412412
custom_trace_attributes: Optional[Mapping[str, AttributeValue]] = None,

tests/strands/agent/test_agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ def test_agent_call_creates_and_ends_span_on_success(mock_get_tracer, mock_model
12311231
# Verify span was created
12321232
mock_tracer.start_agent_span.assert_called_once_with(
12331233
prompt="test prompt",
1234+
agent_name="Strands Agents",
12341235
model_id=unittest.mock.ANY,
12351236
tools=agent.tool_names,
12361237
system_prompt=agent.system_prompt,
@@ -1264,6 +1265,7 @@ async def test_event_loop(*args, **kwargs):
12641265
# Verify span was created
12651266
mock_tracer.start_agent_span.assert_called_once_with(
12661267
prompt="test prompt",
1268+
agent_name="Strands Agents",
12671269
model_id=unittest.mock.ANY,
12681270
tools=agent.tool_names,
12691271
system_prompt=agent.system_prompt,
@@ -1301,6 +1303,7 @@ def test_agent_call_creates_and_ends_span_on_exception(mock_get_tracer, mock_mod
13011303
# Verify span was created
13021304
mock_tracer.start_agent_span.assert_called_once_with(
13031305
prompt="test prompt",
1306+
agent_name="Strands Agents",
13041307
model_id=unittest.mock.ANY,
13051308
tools=agent.tool_names,
13061309
system_prompt=agent.system_prompt,
@@ -1336,6 +1339,7 @@ async def test_agent_stream_async_creates_and_ends_span_on_exception(mock_get_tr
13361339
# Verify span was created
13371340
mock_tracer.start_agent_span.assert_called_once_with(
13381341
prompt="test prompt",
1342+
agent_name="Strands Agents",
13391343
model_id=unittest.mock.ANY,
13401344
tools=agent.tool_names,
13411345
system_prompt=agent.system_prompt,

0 commit comments

Comments
 (0)