MCPcopy Index your code
hub / github.com/langroid/langroid / example0_dsl_syntax

Function example0_dsl_syntax

examples/basic/done_sequences_example.py:62–94  ·  view source on GitHub ↗

Example 0: Using DSL string patterns (recommended for simple cases)

()

Source from the content-addressed store, hash-verified

60
61
62def example0_dsl_syntax():
63 """Example 0: Using DSL string patterns (recommended for simple cases)"""
64 print("\n=== Example 0: DSL String Patterns ===")
65
66 agent = ChatAgent(
67 ChatAgentConfig(
68 name="Assistant",
69 system_message="""
70 You are a helpful assistant with access to calculator and search tools.
71 Use the appropriate tool when asked to calculate or search for something.
72 """,
73 )
74 )
75 agent.enable_message(CalculatorTool, use=True, handle=True)
76 agent.enable_message(SearchTool, use=True, handle=True)
77
78 # Using DSL string patterns - much more concise!
79 config = TaskConfig(
80 done_sequences=[
81 "T, A", # Any tool then agent response
82 "T[calculator], A", # Specific calculator tool
83 "C[quit|exit|bye]", # Content matching pattern
84 "L, T, A, L", # Complex sequence
85 ]
86 )
87
88 _ = Task(agent, config=config)
89 print("Task configured with multiple DSL patterns.")
90 print(
91 "Will complete on any of: tool use, calculator use, quit words, or L->T->A->L sequence"
92 )
93 # _ = task.run("What is 25 * 4?")
94 # print(f"Final result: {result.content}")
95
96
97def example1_tool_then_agent():

Callers 1

Calls 5

enable_messageMethod · 0.95
ChatAgentClass · 0.90
ChatAgentConfigClass · 0.90
TaskConfigClass · 0.90
TaskClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…