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

boolTrue if a section with the given title exists, False otherwise.

Examples

Guard against duplicate sections

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

Conditional prompt assembly in a subclass

1from signalwire import AgentBase
2
3class SupportAgent(AgentBase):
4 def __init__(self):
5 super().__init__(name="support", route="/support")
6 self.prompt_add_section("Tone", body="Be empathetic and professional.")
7
8 def add_escalation_rules(self):
9 if not self.prompt_has_section("Escalation"):
10 self.prompt_add_section("Escalation", bullets=[
11 "Transfer to a human if the caller asks three times.",
12 "Always confirm before transferring."
13 ])