Example 0: Using DSL string patterns (recommended for simple cases)
()
| 60 | |
| 61 | |
| 62 | def 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 | |
| 97 | def example1_tool_then_agent(): |
no test coverage detected
searching dependent graphs…