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

Method usage_examples

langroid/agent/tool_message.py:184–211  ·  view source on GitHub ↗

Instruction to the LLM showing examples of how to use the tool-message. Args: random (bool): whether to pick a random example from the list of examples. Set to `true` when using this to illustrate a dialog between LLM and user.

(cls, random: bool = False)

Source from the content-addressed store, hash-verified

182
183 @classmethod
184 def usage_examples(cls, random: bool = False) -> str:
185 """
186 Instruction to the LLM showing examples of how to use the tool-message.
187
188 Args:
189 random (bool): whether to pick a random example from the list of examples.
190 Set to `true` when using this to illustrate a dialog between LLM and
191 user.
192 (if false, use ALL examples)
193 Returns:
194 str: examples of how to use the tool/function-call
195 """
196 # pick a random example of the fields
197 if len(cls.examples()) == 0:
198 return ""
199 if random:
200 examples = [choice(cls.examples())]
201 else:
202 examples = cls.examples()
203 formatted_examples = [
204 (
205 f"EXAMPLE {i}: (THOUGHT: {ex[0]}) => \n{ex[1].format_example()}"
206 if isinstance(ex, tuple)
207 else f"EXAMPLE {i}:\n {ex.format_example()}"
208 )
209 for i, ex in enumerate(examples, 1)
210 ]
211 return "\n\n".join(formatted_examples)
212
213 def to_json(self) -> str:
214 return self.model_dump_json(indent=4, exclude=self._get_excluded_fields())

Callers 5

format_instructionsMethod · 0.80
format_instructionsMethod · 0.80
tool_instructionsMethod · 0.80
test_usage_instructionFunction · 0.80

Calls 2

examplesMethod · 0.45
format_exampleMethod · 0.45

Tested by 1

test_usage_instructionFunction · 0.64