AgentsAgentBase

prompt_has_section

View as MarkdownOpen in Claude

Check whether a named section already exists in the agent’s POM (Prompt Object Model) prompt. Useful for conditionally adding content to avoid duplicate sections.

Parameters

title
strRequired

The section title to look up. Must match the title passed to prompt_add_section().

Returns

bool — True if a section with the given title exists, False otherwise.

Examples

Guard against duplicate sections

from signalwire import AgentBase
agent = AgentBase(name="assistant", route="/assistant")
agent.prompt_add_section("Greeting", body="Always greet the caller by name.")
if not agent.prompt_has_section("Policies"):
agent.prompt_add_section("Policies", body="Follow company guidelines.")
agent.serve()

Conditional prompt assembly in a subclass

from signalwire import AgentBase
class SupportAgent(AgentBase):
def __init__(self):
super().__init__(name="support", route="/support")
self.prompt_add_section("Tone", body="Be empathetic and professional.")
def add_escalation_rules(self):
if not self.prompt_has_section("Escalation"):
self.prompt_add_section("Escalation", bullets=[
"Transfer to a human if the caller asks three times.",
"Always confirm before transferring."
])