import os def tools_mapping(schema, handler, name=None): tool_name = name or schema["function"]["name"] return {"name": tool_name, "schema": schema, "handler": handler} def tool_schemas(tools_definition): return [t["schema"] for t in tools_definition] def tool_handlers(tools_definition): return {t["name"]: t["handler"] for t in tools_definition} def build_system_prompt(tools_definition): lines = [ "You are a coding agent that assists with software engineering tasks. " "You have access to the following tools:", "" ] for i, tool in enumerate(tools_definition, 1): name = tool["name"] desc = tool["schema"]["function"]["description"] lines.append(f"{i}. {name}: {desc}") lines.extend([ "", "Use tools by returning tool calls when needed. After receiving tool " "results, continue your reasoning. When you have the final answer, " "return it as plain text without tool calls.", "", f"Your workspace directory is: {os.getcwd()}. " "All file operations are relative to this directory.", "", "RAG capabilities (knowledge retrieval):", "- list_collections → see available knowledge bases.", "- inspect_collection → learn metadata fields before searching.", "- search_knowledge → semantic search + optional metadata filter.", "- store_knowledge → save docs with rich metadata for later use.", "", "RAG workflow: inspect → search → reason. Always inspect a collection", "first to discover its metadata keys, then use them in search filters." ]) return "\n".join(lines)