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

Method format_instructions

langroid/agent/tool_message.py:247–278  ·  view source on GitHub ↗

Default Instructions to the LLM showing how to use the tool/function-call. Works for GPT4 but override this for weaker LLMs if needed. Args: tool: instructions for Langroid-native tool use? (e.g. for non-OpenAI LLM) (or else it would be for OpenA

(cls, tool: bool = False)

Source from the content-addressed store, hash-verified

245
246 @classmethod
247 def format_instructions(cls, tool: bool = False) -> str:
248 """
249 Default Instructions to the LLM showing how to use the tool/function-call.
250 Works for GPT4 but override this for weaker LLMs if needed.
251
252 Args:
253 tool: instructions for Langroid-native tool use? (e.g. for non-OpenAI LLM)
254 (or else it would be for OpenAI Function calls).
255 Ignored in the default implementation, but can be used in subclasses.
256 Returns:
257 str: instructions on how to use the message
258 """
259 # TODO: when we attempt to use a "simpler schema"
260 # (i.e. all nested fields explicit without definitions),
261 # we seem to get worse results, so we turn it off for now
262 param_dict = (
263 # cls.simple_schema() if tool else
264 cls.llm_function_schema(request=True).parameters
265 )
266 examples_str = ""
267 if cls.examples():
268 examples_str = "EXAMPLES:\n" + cls.usage_examples()
269 return textwrap.dedent(
270 f"""
271 TOOL: {cls.default_value("request")}
272 PURPOSE: {cls.default_value("purpose")}
273 JSON FORMAT: {
274 json.dumps(param_dict, indent=4)
275 }
276 {examples_str}
277 """.lstrip()
278 )
279
280 @staticmethod
281 def group_format_instructions() -> str:

Callers 3

tool_format_rulesMethod · 0.45
test_instructionsFunction · 0.45

Calls 4

llm_function_schemaMethod · 0.80
usage_examplesMethod · 0.80
default_valueMethod · 0.80
examplesMethod · 0.45

Tested by 2

test_instructionsFunction · 0.36